Skip to content

Commit e0dc8d7

Browse files
committed
Auto merge of rust-lang#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 rust-lang#99854 r? `@oli-obk`
2 parents a8a33cf + 5d7ce21 commit e0dc8d7

File tree

43 files changed

+407
-397
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+407
-397
lines changed

compiler/rustc_mir_build/src/build/mod.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,18 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
250250
// of `mir_build`, so now we can steal it
251251
let thir = thir.steal();
252252

253-
build::construct_const(&thir, &infcx, expr, def, id, return_ty, return_ty_span)
253+
let span_with_body = span_with_body.to(tcx.hir().span(body_id.hir_id));
254+
255+
build::construct_const(
256+
&thir,
257+
&infcx,
258+
expr,
259+
def,
260+
id,
261+
return_ty,
262+
return_ty_span,
263+
span_with_body,
264+
)
254265
};
255266

256267
lints::check(tcx, &body);
@@ -705,9 +716,8 @@ fn construct_const<'a, 'tcx>(
705716
hir_id: hir::HirId,
706717
const_ty: Ty<'tcx>,
707718
const_ty_span: Span,
719+
span: Span,
708720
) -> Body<'tcx> {
709-
let tcx = infcx.tcx;
710-
let span = tcx.hir().span(hir_id);
711721
let mut builder = Builder::new(
712722
thir,
713723
infcx,

compiler/rustc_span/src/source_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ impl SourceMap {
472472
let hi = self.lookup_char_pos(sp.hi());
473473
let offset = self.lookup_char_pos(relative_to.lo());
474474

475-
if lo.file.name != offset.file.name {
475+
if lo.file.name != offset.file.name || !relative_to.contains(sp) {
476476
return self.span_to_embeddable_string(sp);
477477
}
478478

src/test/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstCombine.diff

+37-37
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,63 @@
44
fn <impl at $DIR/combine_clone_of_primitives.rs:6:10: 6:15>::clone(_1: &MyThing<T>) -> MyThing<T> {
55
debug self => _1; // in scope 0 at $DIR/combine_clone_of_primitives.rs:+0:10: +0:15
66
let mut _0: MyThing<T>; // return place in scope 0 at $DIR/combine_clone_of_primitives.rs:+0:10: +0:15
7-
let mut _2: T; // in scope 0 at $DIR/combine_clone_of_primitives.rs:+2:5: +2:9
8-
let mut _3: &T; // in scope 0 at $DIR/combine_clone_of_primitives.rs:+2:5: +2:9
9-
let _4: &T; // in scope 0 at $DIR/combine_clone_of_primitives.rs:+2:5: +2:9
10-
let mut _5: u64; // in scope 0 at $DIR/combine_clone_of_primitives.rs:+3:5: +3:11
11-
let mut _6: &u64; // in scope 0 at $DIR/combine_clone_of_primitives.rs:+3:5: +3:11
12-
let _7: &u64; // in scope 0 at $DIR/combine_clone_of_primitives.rs:+3:5: +3:11
13-
let mut _8: [f32; 3]; // in scope 0 at $DIR/combine_clone_of_primitives.rs:+4:5: +4:16
14-
let mut _9: &[f32; 3]; // in scope 0 at $DIR/combine_clone_of_primitives.rs:+4:5: +4:16
15-
let _10: &[f32; 3]; // in scope 0 at $DIR/combine_clone_of_primitives.rs:+4:5: +4:16
7+
let mut _2: T; // in scope 0 at $DIR/combine_clone_of_primitives.rs:8:5: 8:9
8+
let mut _3: &T; // in scope 0 at $DIR/combine_clone_of_primitives.rs:8:5: 8:9
9+
let _4: &T; // in scope 0 at $DIR/combine_clone_of_primitives.rs:8:5: 8:9
10+
let mut _5: u64; // in scope 0 at $DIR/combine_clone_of_primitives.rs:9:5: 9:11
11+
let mut _6: &u64; // in scope 0 at $DIR/combine_clone_of_primitives.rs:9:5: 9:11
12+
let _7: &u64; // in scope 0 at $DIR/combine_clone_of_primitives.rs:9:5: 9:11
13+
let mut _8: [f32; 3]; // in scope 0 at $DIR/combine_clone_of_primitives.rs:10:5: 10:16
14+
let mut _9: &[f32; 3]; // in scope 0 at $DIR/combine_clone_of_primitives.rs:10:5: 10:16
15+
let _10: &[f32; 3]; // in scope 0 at $DIR/combine_clone_of_primitives.rs:10:5: 10:16
1616

1717
bb0: {
18-
StorageLive(_2); // scope 0 at $DIR/combine_clone_of_primitives.rs:+2:5: +2:9
19-
StorageLive(_3); // scope 0 at $DIR/combine_clone_of_primitives.rs:+2:5: +2:9
20-
StorageLive(_4); // scope 0 at $DIR/combine_clone_of_primitives.rs:+2:5: +2:9
21-
_4 = &((*_1).0: T); // scope 0 at $DIR/combine_clone_of_primitives.rs:+2:5: +2:9
22-
- _3 = &(*_4); // scope 0 at $DIR/combine_clone_of_primitives.rs:+2:5: +2:9
23-
+ _3 = _4; // scope 0 at $DIR/combine_clone_of_primitives.rs:+2:5: +2:9
24-
_2 = <T as Clone>::clone(move _3) -> bb1; // scope 0 at $DIR/combine_clone_of_primitives.rs:+2:5: +2:9
18+
StorageLive(_2); // scope 0 at $DIR/combine_clone_of_primitives.rs:8:5: 8:9
19+
StorageLive(_3); // scope 0 at $DIR/combine_clone_of_primitives.rs:8:5: 8:9
20+
StorageLive(_4); // scope 0 at $DIR/combine_clone_of_primitives.rs:8:5: 8:9
21+
_4 = &((*_1).0: T); // scope 0 at $DIR/combine_clone_of_primitives.rs:8:5: 8:9
22+
- _3 = &(*_4); // scope 0 at $DIR/combine_clone_of_primitives.rs:8:5: 8:9
23+
+ _3 = _4; // scope 0 at $DIR/combine_clone_of_primitives.rs:8:5: 8:9
24+
_2 = <T as Clone>::clone(move _3) -> bb1; // scope 0 at $DIR/combine_clone_of_primitives.rs:8:5: 8:9
2525
// mir::Constant
2626
// + span: $DIR/combine_clone_of_primitives.rs:8:5: 8:9
2727
// + literal: Const { ty: for<'r> fn(&'r T) -> T {<T as Clone>::clone}, val: Value(<ZST>) }
2828
}
2929

3030
bb1: {
31-
StorageDead(_3); // scope 0 at $DIR/combine_clone_of_primitives.rs:+2:8: +2:9
32-
StorageLive(_5); // scope 0 at $DIR/combine_clone_of_primitives.rs:+3:5: +3:11
33-
StorageLive(_6); // scope 0 at $DIR/combine_clone_of_primitives.rs:+3:5: +3:11
34-
StorageLive(_7); // scope 0 at $DIR/combine_clone_of_primitives.rs:+3:5: +3:11
35-
_7 = &((*_1).1: u64); // scope 0 at $DIR/combine_clone_of_primitives.rs:+3:5: +3:11
36-
- _6 = &(*_7); // scope 0 at $DIR/combine_clone_of_primitives.rs:+3:5: +3:11
37-
- _5 = <u64 as Clone>::clone(move _6) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/combine_clone_of_primitives.rs:+3:5: +3:11
31+
StorageDead(_3); // scope 0 at $DIR/combine_clone_of_primitives.rs:8:8: 8:9
32+
StorageLive(_5); // scope 0 at $DIR/combine_clone_of_primitives.rs:9:5: 9:11
33+
StorageLive(_6); // scope 0 at $DIR/combine_clone_of_primitives.rs:9:5: 9:11
34+
StorageLive(_7); // scope 0 at $DIR/combine_clone_of_primitives.rs:9:5: 9:11
35+
_7 = &((*_1).1: u64); // scope 0 at $DIR/combine_clone_of_primitives.rs:9:5: 9:11
36+
- _6 = &(*_7); // scope 0 at $DIR/combine_clone_of_primitives.rs:9:5: 9:11
37+
- _5 = <u64 as Clone>::clone(move _6) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/combine_clone_of_primitives.rs:9:5: 9:11
3838
- // mir::Constant
3939
- // + span: $DIR/combine_clone_of_primitives.rs:9:5: 9:11
4040
- // + literal: Const { ty: for<'r> fn(&'r u64) -> u64 {<u64 as Clone>::clone}, val: Value(<ZST>) }
41-
+ _6 = _7; // scope 0 at $DIR/combine_clone_of_primitives.rs:+3:5: +3:11
42-
+ _5 = (*_6); // scope 0 at $DIR/combine_clone_of_primitives.rs:+3:5: +3:11
43-
+ goto -> bb2; // scope 0 at $DIR/combine_clone_of_primitives.rs:+3:5: +3:11
41+
+ _6 = _7; // scope 0 at $DIR/combine_clone_of_primitives.rs:9:5: 9:11
42+
+ _5 = (*_6); // scope 0 at $DIR/combine_clone_of_primitives.rs:9:5: 9:11
43+
+ goto -> bb2; // scope 0 at $DIR/combine_clone_of_primitives.rs:9:5: 9:11
4444
}
4545

4646
bb2: {
47-
StorageDead(_6); // scope 0 at $DIR/combine_clone_of_primitives.rs:+3:10: +3:11
48-
StorageLive(_8); // scope 0 at $DIR/combine_clone_of_primitives.rs:+4:5: +4:16
49-
StorageLive(_9); // scope 0 at $DIR/combine_clone_of_primitives.rs:+4:5: +4:16
50-
StorageLive(_10); // scope 0 at $DIR/combine_clone_of_primitives.rs:+4:5: +4:16
51-
_10 = &((*_1).2: [f32; 3]); // scope 0 at $DIR/combine_clone_of_primitives.rs:+4:5: +4:16
52-
- _9 = &(*_10); // scope 0 at $DIR/combine_clone_of_primitives.rs:+4:5: +4:16
53-
- _8 = <[f32; 3] as Clone>::clone(move _9) -> [return: bb3, unwind: bb4]; // scope 0 at $DIR/combine_clone_of_primitives.rs:+4:5: +4:16
47+
StorageDead(_6); // scope 0 at $DIR/combine_clone_of_primitives.rs:9:10: 9:11
48+
StorageLive(_8); // scope 0 at $DIR/combine_clone_of_primitives.rs:10:5: 10:16
49+
StorageLive(_9); // scope 0 at $DIR/combine_clone_of_primitives.rs:10:5: 10:16
50+
StorageLive(_10); // scope 0 at $DIR/combine_clone_of_primitives.rs:10:5: 10:16
51+
_10 = &((*_1).2: [f32; 3]); // scope 0 at $DIR/combine_clone_of_primitives.rs:10:5: 10:16
52+
- _9 = &(*_10); // scope 0 at $DIR/combine_clone_of_primitives.rs:10:5: 10:16
53+
- _8 = <[f32; 3] as Clone>::clone(move _9) -> [return: bb3, unwind: bb4]; // scope 0 at $DIR/combine_clone_of_primitives.rs:10:5: 10:16
5454
- // mir::Constant
5555
- // + span: $DIR/combine_clone_of_primitives.rs:10:5: 10:16
5656
- // + literal: Const { ty: for<'r> fn(&'r [f32; 3]) -> [f32; 3] {<[f32; 3] as Clone>::clone}, val: Value(<ZST>) }
57-
+ _9 = _10; // scope 0 at $DIR/combine_clone_of_primitives.rs:+4:5: +4:16
58-
+ _8 = (*_9); // scope 0 at $DIR/combine_clone_of_primitives.rs:+4:5: +4:16
59-
+ goto -> bb3; // scope 0 at $DIR/combine_clone_of_primitives.rs:+4:5: +4:16
57+
+ _9 = _10; // scope 0 at $DIR/combine_clone_of_primitives.rs:10:5: 10:16
58+
+ _8 = (*_9); // scope 0 at $DIR/combine_clone_of_primitives.rs:10:5: 10:16
59+
+ goto -> bb3; // scope 0 at $DIR/combine_clone_of_primitives.rs:10:5: 10:16
6060
}
6161

6262
bb3: {
63-
StorageDead(_9); // scope 0 at $DIR/combine_clone_of_primitives.rs:+4:15: +4:16
63+
StorageDead(_9); // scope 0 at $DIR/combine_clone_of_primitives.rs:10:15: 10:16
6464
Deinit(_0); // scope 0 at $DIR/combine_clone_of_primitives.rs:+0:10: +0:15
6565
(_0.0: T) = move _2; // scope 0 at $DIR/combine_clone_of_primitives.rs:+0:10: +0:15
6666
(_0.1: u64) = move _5; // scope 0 at $DIR/combine_clone_of_primitives.rs:+0:10: +0:15

src/test/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
- StorageDead(_5); // scope 0 at $DIR/const-promotion-extern-static.rs:+0:43: +0:44
4141
- StorageDead(_3); // scope 0 at $DIR/const-promotion-extern-static.rs:+0:43: +0:44
4242
StorageDead(_1); // scope 0 at $DIR/const-promotion-extern-static.rs:+0:43: +0:44
43-
return; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:1: +0:28
43+
return; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:1: +0:44
4444
}
4545

4646
bb2 (cleanup): {
47-
resume; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:1: +0:28
47+
resume; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:1: +0:44
4848
}
4949
- }
5050
-

src/test/mir-opt/const_promotion_extern_static.BOP.mir_map.0.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ static BOP: &i32 = {
1212
_1 = &_2; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:20: +0:23
1313
_0 = &(*_1); // scope 0 at $DIR/const-promotion-extern-static.rs:+0:20: +0:23
1414
StorageDead(_1); // scope 0 at $DIR/const-promotion-extern-static.rs:+0:22: +0:23
15-
return; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:1: +0:17
15+
return; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:1: +0:23
1616
}
1717
}

src/test/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
- StorageDead(_5); // scope 0 at $DIR/const-promotion-extern-static.rs:+0:54: +0:55
4343
- StorageDead(_3); // scope 0 at $DIR/const-promotion-extern-static.rs:+0:54: +0:55
4444
StorageDead(_1); // scope 0 at $DIR/const-promotion-extern-static.rs:+0:54: +0:55
45-
return; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:1: +0:28
45+
return; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:1: +0:55
4646
}
4747

4848
bb2 (cleanup): {
49-
resume; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:1: +0:28
49+
resume; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:1: +0:55
5050
}
5151
}
5252
-

src/test/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.mir

+13-13
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
fn main::{closure#0}(_1: *mut [generator@$DIR/generator-drop-cleanup.rs:10:15: 10:17]) -> () {
1818
let mut _0: (); // return place in scope 0 at $DIR/generator-drop-cleanup.rs:+0:15: +0:17
1919
let mut _2: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:+0:15: +0:17
20-
let _3: std::string::String; // in scope 0 at $DIR/generator-drop-cleanup.rs:+1:13: +1:15
21-
let _4: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:+2:9: +2:14
22-
let mut _5: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:+2:9: +2:14
23-
let mut _6: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:+0:18: +0:18
20+
let _3: std::string::String; // in scope 0 at $DIR/generator-drop-cleanup.rs:11:13: 11:15
21+
let _4: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:12:9: 12:14
22+
let mut _5: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:12:9: 12:14
23+
let mut _6: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:10:18: 10:18
2424
let mut _7: (); // in scope 0 at $DIR/generator-drop-cleanup.rs:+0:15: +0:17
2525
let mut _8: u32; // in scope 0 at $DIR/generator-drop-cleanup.rs:+0:15: +0:17
2626
scope 1 {
27-
debug _s => (((*_1) as variant#3).0: std::string::String); // in scope 1 at $DIR/generator-drop-cleanup.rs:+1:13: +1:15
27+
debug _s => (((*_1) as variant#3).0: std::string::String); // in scope 1 at $DIR/generator-drop-cleanup.rs:11:13: 11:15
2828
}
2929

3030
bb0: {
@@ -33,14 +33,14 @@ fn main::{closure#0}(_1: *mut [generator@$DIR/generator-drop-cleanup.rs:10:15: 1
3333
}
3434

3535
bb1: {
36-
StorageDead(_5); // scope 1 at $DIR/generator-drop-cleanup.rs:+2:13: +2:14
37-
StorageDead(_4); // scope 1 at $DIR/generator-drop-cleanup.rs:+2:14: +2:15
38-
drop((((*_1) as variant#3).0: std::string::String)) -> [return: bb2, unwind: bb5]; // scope 0 at $DIR/generator-drop-cleanup.rs:+3:5: +3:6
36+
StorageDead(_5); // scope 1 at $DIR/generator-drop-cleanup.rs:12:13: 12:14
37+
StorageDead(_4); // scope 1 at $DIR/generator-drop-cleanup.rs:12:14: 12:15
38+
drop((((*_1) as variant#3).0: std::string::String)) -> [return: bb2, unwind: bb5]; // scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6
3939
}
4040

4141
bb2: {
42-
nop; // scope 0 at $DIR/generator-drop-cleanup.rs:+3:5: +3:6
43-
goto -> bb8; // scope 0 at $DIR/generator-drop-cleanup.rs:+3:5: +3:6
42+
nop; // scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6
43+
goto -> bb8; // scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6
4444
}
4545

4646
bb3: {
@@ -52,8 +52,8 @@ fn main::{closure#0}(_1: *mut [generator@$DIR/generator-drop-cleanup.rs:10:15: 1
5252
}
5353

5454
bb5 (cleanup): {
55-
nop; // scope 0 at $DIR/generator-drop-cleanup.rs:+3:5: +3:6
56-
goto -> bb4; // scope 0 at $DIR/generator-drop-cleanup.rs:+3:5: +3:6
55+
nop; // scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6
56+
goto -> bb4; // scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6
5757
}
5858

5959
bb6: {
@@ -65,7 +65,7 @@ fn main::{closure#0}(_1: *mut [generator@$DIR/generator-drop-cleanup.rs:10:15: 1
6565
}
6666

6767
bb8: {
68-
goto -> bb3; // scope 0 at $DIR/generator-drop-cleanup.rs:+3:5: +3:6
68+
goto -> bb3; // scope 0 at $DIR/generator-drop-cleanup.rs:13:5: 13:6
6969
}
7070

7171
bb9: {

0 commit comments

Comments
 (0)