Skip to content

Commit 2ddca19

Browse files
committedApr 12, 2024
Error on using yield without also using #[coroutine] on the closure
And suggest adding the `#[coroutine]` to the closure
1 parent 2a3779b commit 2ddca19

File tree

266 files changed

+1227
-829
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

266 files changed

+1227
-829
lines changed
 

‎compiler/rustc_ast_lowering/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,6 @@ ast_lowering_underscore_expr_lhs_assign =
161161
.label = `_` not allowed here
162162
163163
ast_lowering_use_angle_brackets = use angle brackets instead
164+
ast_lowering_yield_in_closure =
165+
`yield` can only be used in `#[coroutine]` closures, or `gen` blocks
166+
.suggestion = use `#[coroutine]` to make this closure a coroutine

‎compiler/rustc_ast_lowering/src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,12 @@ pub(crate) struct AsyncBoundOnlyForFnTraits {
414414
#[primary_span]
415415
pub span: Span,
416416
}
417+
418+
#[derive(Diagnostic)]
419+
#[diag(ast_lowering_yield_in_closure)]
420+
pub(crate) struct YieldInClosure {
421+
#[primary_span]
422+
pub span: Span,
423+
#[suggestion(code = "#[coroutine] ", applicability = "maybe-incorrect", style = "verbose")]
424+
pub suggestion: Option<Span>,
425+
}

0 commit comments

Comments
 (0)