Skip to content

Commit aef0f40

Browse files
committedApr 24, 2024·
Error on using yield without also using #[coroutine] on the closure
And suggest adding the `#[coroutine]` to the closure
1 parent a589632 commit aef0f40

File tree

279 files changed

+1293
-889
lines changed

Some content is hidden

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

279 files changed

+1293
-889
lines changed
 

‎compiler/rustc_ast_lowering/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,6 @@ ast_lowering_underscore_expr_lhs_assign =
163163
.label = `_` not allowed here
164164
165165
ast_lowering_use_angle_brackets = use angle brackets instead
166+
ast_lowering_yield_in_closure =
167+
`yield` can only be used in `#[coroutine]` closures, or `gen` blocks
168+
.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
@@ -421,3 +421,12 @@ pub(crate) struct NoPreciseCapturesOnApit {
421421
#[primary_span]
422422
pub span: Span,
423423
}
424+
425+
#[derive(Diagnostic)]
426+
#[diag(ast_lowering_yield_in_closure)]
427+
pub(crate) struct YieldInClosure {
428+
#[primary_span]
429+
pub span: Span,
430+
#[suggestion(code = "#[coroutine] ", applicability = "maybe-incorrect", style = "verbose")]
431+
pub suggestion: Option<Span>,
432+
}

0 commit comments

Comments
 (0)
Please sign in to comment.