diff options
Diffstat (limited to 'compiler/rustc_ast_lowering/src')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/expr.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_ast_lowering/src/item.rs | 16 |
2 files changed, 13 insertions, 10 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 79cff0fbcd2..624bca525b9 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -227,7 +227,7 @@ impl<'hir> LoweringContext<'_, 'hir> { *fn_arg_span, ), }, - ExprKind::Gen(capture_clause, block, genblock_kind) => { + ExprKind::Gen(capture_clause, block, genblock_kind, decl_span) => { let desugaring_kind = match genblock_kind { GenBlockKind::Async => hir::CoroutineDesugaring::Async, GenBlockKind::Gen => hir::CoroutineDesugaring::Gen, @@ -237,6 +237,7 @@ impl<'hir> LoweringContext<'_, 'hir> { *capture_clause, e.id, None, + *decl_span, e.span, desugaring_kind, hir::CoroutineSource::Block, @@ -616,6 +617,7 @@ impl<'hir> LoweringContext<'_, 'hir> { capture_clause: CaptureBy, closure_node_id: NodeId, return_ty: Option<hir::FnRetTy<'hir>>, + fn_decl_span: Span, span: Span, desugaring_kind: hir::CoroutineDesugaring, coroutine_source: hir::CoroutineSource, @@ -692,7 +694,7 @@ impl<'hir> LoweringContext<'_, 'hir> { bound_generic_params: &[], fn_decl, body, - fn_decl_span: self.lower_span(span), + fn_decl_span: self.lower_span(fn_decl_span), fn_arg_span: None, kind: hir::ClosureKind::Coroutine(coroutine_kind), constness: hir::Constness::NotConst, @@ -1083,6 +1085,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let (parameters, expr) = this.lower_coroutine_body_with_moved_arguments( &inner_decl, |this| this.with_new_scopes(fn_decl_span, |this| this.lower_expr_mut(body)), + fn_decl_span, body.span, coroutine_kind, hir::CoroutineSource::Closure, diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 4c7e8c24d32..74e04eff4f3 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -211,6 +211,7 @@ impl<'hir> LoweringContext<'_, 'hir> { // declaration (decl), not the return types. let coroutine_kind = header.coroutine_kind; let body_id = this.lower_maybe_coroutine_body( + *fn_sig_span, span, hir_id, decl, @@ -799,6 +800,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } AssocItemKind::Fn(box Fn { sig, generics, body: Some(body), .. }) => { let body_id = self.lower_maybe_coroutine_body( + sig.span, i.span, hir_id, &sig.decl, @@ -915,6 +917,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ), AssocItemKind::Fn(box Fn { sig, generics, body, .. }) => { let body_id = self.lower_maybe_coroutine_body( + sig.span, i.span, hir_id, &sig.decl, @@ -1111,6 +1114,7 @@ impl<'hir> LoweringContext<'_, 'hir> { /// `gen {}` block as appropriate. fn lower_maybe_coroutine_body( &mut self, + fn_decl_span: Span, span: Span, fn_id: hir::HirId, decl: &FnDecl, @@ -1124,6 +1128,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let (parameters, expr) = this.lower_coroutine_body_with_moved_arguments( decl, |this| this.lower_block_expr(body), + fn_decl_span, body.span, coroutine_kind, hir::CoroutineSource::Fn, @@ -1145,6 +1150,7 @@ impl<'hir> LoweringContext<'_, 'hir> { &mut self, decl: &FnDecl, lower_body: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::Expr<'hir>, + fn_decl_span: Span, body_span: Span, coroutine_kind: CoroutineKind, coroutine_source: hir::CoroutineSource, @@ -1315,13 +1321,6 @@ impl<'hir> LoweringContext<'_, 'hir> { }; let closure_id = coroutine_kind.closure_id(); - let span = if let FnRetTy::Default(span) = decl.output - && matches!(coroutine_source, rustc_hir::CoroutineSource::Closure) - { - body_span.with_lo(span.lo()) - } else { - body_span - }; let coroutine_expr = self.make_desugared_coroutine_expr( // The default capture mode here is by-ref. Later on during upvar analysis, // we will force the captured arguments to by-move, but for async closures, @@ -1330,7 +1329,8 @@ impl<'hir> LoweringContext<'_, 'hir> { CaptureBy::Ref, closure_id, None, - span, + fn_decl_span, + body_span, desugaring_kind, coroutine_source, mkbody, |
