Skip to content

Commit

Permalink
rustc_ast_lowering: make "yield syntax is experimental" translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigorenkoPV committed Aug 10, 2024
1 parent 334a097 commit 290df4f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_ast_lowering/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ ast_lowering_underscore_expr_lhs_assign =
.label = `_` not allowed here
ast_lowering_use_angle_brackets = use angle brackets instead
ast_lowering_yield = yield syntax is experimental
ast_lowering_yield_in_closure =
`yield` can only be used in `#[coroutine]` closures, or `gen` blocks
.suggestion = use `#[coroutine]` to make this closure a coroutine
7 changes: 3 additions & 4 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use super::{
ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs, ResolverAstLoweringExt,
};
use crate::errors::YieldInClosure;
use crate::{FnDeclKind, ImplTraitPosition};
use crate::{fluent_generated, FnDeclKind, ImplTraitPosition};

impl<'hir> LoweringContext<'_, 'hir> {
fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> &'hir [hir::Expr<'hir>] {
Expand Down Expand Up @@ -1540,7 +1540,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}

#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> {
let yielded =
opt_expr.as_ref().map(|x| self.lower_expr(x)).unwrap_or_else(|| self.expr_unit(span));
Expand Down Expand Up @@ -1575,7 +1574,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&self.tcx.sess,
sym::coroutines,
span,
"yield syntax is experimental",
fluent_generated::ast_lowering_yield,
)
.emit();
}
Expand All @@ -1587,7 +1586,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&self.tcx.sess,
sym::coroutines,
span,
"yield syntax is experimental",
fluent_generated::ast_lowering_yield,
)
.emit();
}
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/coroutine/gen_block.none.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ LL | let _ = || yield true;
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(coroutines)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
--> $DIR/gen_block.rs:16:16
Expand All @@ -95,7 +94,6 @@ LL | let _ = #[coroutine] || yield true;
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(coroutines)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 11 previous errors

Expand Down
2 changes: 0 additions & 2 deletions tests/ui/feature-gates/feature-gate-coroutines.none.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ LL | yield true;
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(coroutines)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
--> $DIR/feature-gate-coroutines.rs:5:5
Expand All @@ -69,7 +68,6 @@ LL | let _ = || yield true;
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(coroutines)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
--> $DIR/feature-gate-coroutines.rs:10:16
Expand Down

0 comments on commit 290df4f

Please sign in to comment.