Skip to content

Commit 817bc67

Browse files
authored
Unrolled build for #144190
Rollup merge of #144190 - scottmcm:spanned-errors-in-mir-validation, r=RalfJung Give a message with a span on MIR validation error It was handy to get a source+line link for #143833, even if it's just to the function and not necessarily to the statement. r? mir
2 parents ca9eecd + 14d097f commit 817bc67

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

compiler/rustc_mir_transform/src/validate.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,16 @@ impl<'a, 'tcx> CfgChecker<'a, 'tcx> {
119119
#[track_caller]
120120
fn fail(&self, location: Location, msg: impl AsRef<str>) {
121121
// We might see broken MIR when other errors have already occurred.
122-
assert!(
123-
self.tcx.dcx().has_errors().is_some(),
124-
"broken MIR in {:?} ({}) at {:?}:\n{}",
125-
self.body.source.instance,
126-
self.when,
127-
location,
128-
msg.as_ref(),
129-
);
122+
if self.tcx.dcx().has_errors().is_none() {
123+
span_bug!(
124+
self.body.source_info(location).span,
125+
"broken MIR in {:?} ({}) at {:?}:\n{}",
126+
self.body.source.instance,
127+
self.when,
128+
location,
129+
msg.as_ref(),
130+
);
131+
}
130132
}
131133

132134
fn check_edge(&mut self, location: Location, bb: BasicBlock, edge_kind: EdgeKind) {

src/tools/miri/tests/panic/mir-validation.stderr

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
error: internal compiler error: compiler/rustc_mir_transform/src/validate.rs:LL:CC: broken MIR in Item(DefId) (after phase change to runtime-optimized) at bb0[1]:
2+
place (*(_2.0: *mut i32)) has deref as a later projection (it is only permitted as the first projection)
3+
--> tests/panic/mir-validation.rs:LL:CC
4+
|
5+
LL | *(tuple.0) = 1;
6+
| ^^^^^^^^^^^^^^
7+
18

29
thread 'rustc' panicked at compiler/rustc_mir_transform/src/validate.rs:LL:CC:
3-
broken MIR in Item(DefId) (after phase change to runtime-optimized) at bb0[1]:
4-
place (*(_2.0: *mut i32)) has deref as a later projection (it is only permitted as the first projection)
10+
Box<dyn Any>
511
stack backtrace:
612

7-
error: the compiler unexpectedly panicked. this is a bug.
8-
913

1014

1115

@@ -20,3 +24,5 @@ LL | extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
2024
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2125
|
2226

27+
error: aborting due to 1 previous error
28+

tests/ui/mir/validate/critical-edge.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub fn f(a: u32) -> u32 {
2121
}
2222
bb1 = {
2323
Call(RET = f(1), ReturnTo(bb2), UnwindTerminate(ReasonAbi))
24+
//~^ ERROR broken MIR in Item
25+
//~| ERROR encountered critical edge in `Call` terminator
2426
}
2527

2628
bb2 = {
@@ -29,5 +31,3 @@ pub fn f(a: u32) -> u32 {
2931
}
3032
}
3133
}
32-
33-
//~? RAW encountered critical edge in `Call` terminator

0 commit comments

Comments
 (0)