about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-08-22 14:59:21 +0000
committerbors <bors@rust-lang.org>2022-08-22 14:59:21 +0000
commite0dc8d78019ca924203fe153ff0af7f64f68cb5d (patch)
treeb23cb7ef4b6ce43fa21873e78c078c7fe9b1d6ee /compiler
parenta8a33cf27166d3eabaffc58ed3799e054af3b0c6 (diff)
parent5d7ce21b6ba31e93d7d9af71dd330ecc71387a2d (diff)
downloadrust-e0dc8d78019ca924203fe153ff0af7f64f68cb5d.tar.gz
rust-e0dc8d78019ca924203fe153ff0af7f64f68cb5d.zip
Auto merge of #99908 - Nilstrieb:mir-opt-span, r=oli-obk
Show absolute line numbers if span is outside relative span

In the MIR pretty printing, it can sometimes happen that the span of the statement is outside the span of the body (for example through inlining). In this case, don't display a relative span but an absolute span. This will make the mir-opt-tests a little more prone to diffs again, but the impact should be small.

Fixes #99854

r? `@oli-obk`
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_mir_build/src/build/mod.rs16
-rw-r--r--compiler/rustc_span/src/source_map.rs2
2 files changed, 14 insertions, 4 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<LocalDefId>) -> 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,
diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs
index bc76ccc1d59..5f928707ea8 100644
--- a/compiler/rustc_span/src/source_map.rs
+++ b/compiler/rustc_span/src/source_map.rs
@@ -472,7 +472,7 @@ impl SourceMap {
         let hi = self.lookup_char_pos(sp.hi());
         let offset = self.lookup_char_pos(relative_to.lo());
 
-        if lo.file.name != offset.file.name {
+        if lo.file.name != offset.file.name || !relative_to.contains(sp) {
             return self.span_to_embeddable_string(sp);
         }