diff options
Diffstat (limited to 'compiler/rustc_ast_lowering/src/expr.rs')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/expr.rs | 44 | 
1 files changed, 26 insertions, 18 deletions
| diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 66841c094ce..eb206a09be3 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::*; @@ -74,12 +75,8 @@ impl<'hir> LoweringContext<'_, 'hir> { let kind = match &e.kind { ExprKind::Array(exprs) => hir::ExprKind::Array(self.lower_exprs(exprs)), ExprKind::ConstBlock(c) => { - let c = self.with_new_scopes(c.value.span, |this| hir::ConstBlock { - def_id: this.local_def_id(c.id), - hir_id: this.lower_node_id(c.id), - body: this.lower_const_body(c.value.span, Some(&c.value)), - }); - hir::ExprKind::ConstBlock(c) + self.has_inline_consts = true; + hir::ExprKind::ConstBlock(self.lower_expr(c)) } ExprKind::Repeat(expr, count) => { let expr = self.lower_expr(expr); @@ -157,13 +154,13 @@ impl<'hir> LoweringContext<'_, 'hir> { let ohs = self.lower_expr(ohs); hir::ExprKind::AddrOf(*k, *m, ohs) } - ExprKind::Let(pat, scrutinee, span, is_recovered) => { + ExprKind::Let(pat, scrutinee, span, recovered) => { hir::ExprKind::Let(self.arena.alloc(hir::LetExpr { span: self.lower_span(*span), pat: self.lower_pat(pat), ty: None, init: self.lower_expr(scrutinee), - is_recovered: *is_recovered, + recovered: *recovered, })) } ExprKind::If(cond, then, else_opt) => { @@ -217,6 +214,7 @@ impl<'hir> LoweringContext<'_, 'hir> { binder, *capture_clause, e.id, + hir_id, *constness, *movability, fn_decl, @@ -579,8 +577,8 @@ impl<'hir> LoweringContext<'_, 'hir> { self.dcx().emit_err(NeverPatternWithGuard { span: g.span }); } - // We add a fake `loop {}` arm body so that it typecks to `!`. - // FIXME(never_patterns): Desugar into a call to `unreachable_unchecked`. + // We add a fake `loop {}` arm body so that it typecks to `!`. The mir lowering of never + // patterns ensures this loop is not reachable. let block = self.arena.alloc(hir::Block { stmts: &[], expr: None, @@ -643,7 +641,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let (pat, task_context_hid) = self.pat_ident_binding_mode( span, Ident::with_dummy_span(sym::_task_context), - hir::BindingAnnotation::MUT, + hir::BindingMode::MUT, ); let param = hir::Param { hir_id: self.next_id(), @@ -805,11 +803,8 @@ impl<'hir> LoweringContext<'_, 'hir> { // debuggers and debugger extensions expect it to be called `__awaitee`. They use // this name to identify what is being awaited by a suspended async functions. let awaitee_ident = Ident::with_dummy_span(sym::__awaitee); - let (awaitee_pat, awaitee_pat_hid) = self.pat_ident_binding_mode( - gen_future_span, - awaitee_ident, - hir::BindingAnnotation::MUT, - ); + let (awaitee_pat, awaitee_pat_hid) = + self.pat_ident_binding_mode(gen_future_span, awaitee_ident, hir::BindingMode::MUT); let task_context_ident = Ident::with_dummy_span(sym::_task_context); @@ -958,6 +953,7 @@ impl<'hir> LoweringContext<'_, 'hir> { binder: &ClosureBinder, capture_clause: CaptureBy, closure_id: NodeId, + closure_hir_id: hir::HirId, constness: Const, movability: Movability, decl: &FnDecl, @@ -968,8 +964,17 @@ impl<'hir> LoweringContext<'_, 'hir> { let (binder_clause, generic_params) = self.lower_closure_binder(binder); let (body_id, closure_kind) = self.with_new_scopes(fn_decl_span, move |this| { - let mut coroutine_kind = None; + let mut coroutine_kind = if this + .attrs + .get(&closure_hir_id.local_id) + .is_some_and(|attrs| attrs.iter().any(|attr| attr.has_name(sym::coroutine))) + { + Some(hir::CoroutineKind::Coroutine(Movability::Movable)) + } else { + 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 @@ -1568,7 +1573,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 } }; @@ -1648,7 +1656,7 @@ impl<'hir> LoweringContext<'_, 'hir> { // `mut iter` let iter = Ident::with_dummy_span(sym::iter); let (iter_pat, iter_pat_nid) = - self.pat_ident_binding_mode(head_span, iter, hir::BindingAnnotation::MUT); + self.pat_ident_binding_mode(head_span, iter, hir::BindingMode::MUT); let match_expr = { let iter = self.expr_ident(head_span, iter, iter_pat_nid); | 
