diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-04-11 13:15:34 +0000 | 
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-04-24 08:05:29 +0000 | 
| commit | aef0f4024aec24fd7e53dbc51883457e44fe17ce (patch) | |
| tree | 25a26930a8cc3441951ba159f1a632092df41655 /compiler/rustc_ast_lowering/src/expr.rs | |
| parent | a589632dad58c2669b7984019efb59917a16ac67 (diff) | |
| download | rust-aef0f4024aec24fd7e53dbc51883457e44fe17ce.tar.gz rust-aef0f4024aec24fd7e53dbc51883457e44fe17ce.zip | |
Error on using `yield` without also using `#[coroutine]` on the closure
And suggest adding the `#[coroutine]` to the closure
Diffstat (limited to 'compiler/rustc_ast_lowering/src/expr.rs')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/expr.rs | 5 | 
1 files changed, 5 insertions, 0 deletions
| diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 6c3f0343147..5cc05d7336e 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -8,6 +8,7 @@ use super::errors::{ }; use super::ResolverAstLoweringExt; use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs}; +use crate::errors::YieldInClosure; use crate::{FnDeclKind, ImplTraitPosition}; use rustc_ast::ptr::P as AstP; use rustc_ast::*; @@ -977,6 +978,7 @@ impl<'hir> LoweringContext<'_, 'hir> { None }; let body_id = this.lower_fn_body(decl, |this| { + this.coroutine_kind = coroutine_kind; let e = this.lower_expr_mut(body); coroutine_kind = this.coroutine_kind; e @@ -1575,7 +1577,10 @@ impl<'hir> LoweringContext<'_, 'hir> { ) .emit(); } + let suggestion = self.current_item.map(|s| s.shrink_to_lo()); + self.dcx().emit_err(YieldInClosure { span, suggestion }); self.coroutine_kind = Some(hir::CoroutineKind::Coroutine(Movability::Movable)); + false } }; | 
