Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6929fdd

Browse files
Compute layout with spans for better cycle errors in coroutines
1 parent 0793ddf commit 6929fdd

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
792792
// debuggers and debugger extensions expect it to be called `__awaitee`. They use
793793
// this name to identify what is being awaited by a suspended async functions.
794794
let awaitee_ident = Ident::with_dummy_span(sym::__awaitee);
795-
let (awaitee_pat, awaitee_pat_hid) =
796-
self.pat_ident_binding_mode(span, awaitee_ident, hir::BindingAnnotation::MUT);
795+
let (awaitee_pat, awaitee_pat_hid) = self.pat_ident_binding_mode(
796+
gen_future_span,
797+
awaitee_ident,
798+
hir::BindingAnnotation::MUT,
799+
);
797800

798801
let task_context_ident = Ident::with_dummy_span(sym::_task_context);
799802

compiler/rustc_ty_utils/src/layout.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -740,11 +740,11 @@ fn coroutine_layout<'tcx>(
740740
};
741741
let tag_layout = cx.tcx.mk_layout(LayoutS::scalar(cx, tag));
742742

743-
let promoted_layouts = ineligible_locals
744-
.iter()
745-
.map(|local| subst_field(info.field_tys[local].ty))
746-
.map(|ty| Ty::new_maybe_uninit(tcx, ty))
747-
.map(|ty| Ok(cx.layout_of(ty)?.layout));
743+
let promoted_layouts = ineligible_locals.iter().map(|local| {
744+
let field_ty = subst_field(info.field_tys[local].ty);
745+
let uninit_ty = Ty::new_maybe_uninit(tcx, field_ty);
746+
Ok(cx.spanned_layout_of(uninit_ty, info.field_tys[local].source_info.span)?.layout)
747+
});
748748
let prefix_layouts = args
749749
.as_coroutine()
750750
.prefix_tys()

tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Static,
1515
),
1616
source_info: SourceInfo {
17-
span: $DIR/async_await.rs:16:9: 16:14 (#8),
17+
span: $DIR/async_await.rs:16:5: 16:14 (#9),
1818
scope: scope[0],
1919
},
2020
ignore_for_traits: false,
@@ -32,7 +32,7 @@
3232
Static,
3333
),
3434
source_info: SourceInfo {
35-
span: $DIR/async_await.rs:17:9: 17:14 (#10),
35+
span: $DIR/async_await.rs:17:5: 17:14 (#11),
3636
scope: scope[0],
3737
},
3838
ignore_for_traits: false,

0 commit comments

Comments
 (0)