From 135c24102c25aefb64cd5dea816c8327bb907513 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Fri, 29 Jul 2022 18:49:27 +0200 Subject: [PATCH] Fix span for consts in mir builder --- compiler/rustc_mir_build/src/build/mod.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index 12b8ceede0f..461c837f6df 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -250,7 +250,18 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam) -> Body<'_ // of `mir_build`, so now we can steal it let thir = thir.steal(); - build::construct_const(&thir, &infcx, expr, def, id, return_ty, return_ty_span) + let span_with_body = span_with_body.to(tcx.hir().span(body_id.hir_id)); + + build::construct_const( + &thir, + &infcx, + expr, + def, + id, + return_ty, + return_ty_span, + span_with_body, + ) }; lints::check(tcx, &body); @@ -705,9 +716,8 @@ fn construct_const<'a, 'tcx>( hir_id: hir::HirId, const_ty: Ty<'tcx>, const_ty_span: Span, + span: Span, ) -> Body<'tcx> { - let tcx = infcx.tcx; - let span = tcx.hir().span(hir_id); let mut builder = Builder::new( thir, infcx,