Skip to content

Commit 5887204

Browse files
committed
Give a message with a span on validation error
1 parent 8f08b3a commit 5887204

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
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.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: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
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 | / pub fn main() {
6+
LL | | mir! {
7+
LL | | let x: i32;
8+
LL | | let tuple: (*mut i32,);
9+
... |
10+
LL | | }
11+
| |_^
12+
113

214
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)
15+
Box<dyn Any>
516
stack backtrace:
617

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

1019

1120

1221
query stack during panic:
1322
#0 [optimized_mir] optimizing MIR for `main`
1423
end of query stack
15-
16-
Miri caused an ICE during evaluation. Here's the interpreter backtrace at the time of the panic:
17-
--> RUSTLIB/core/src/ops/function.rs:LL:CC
18-
|
19-
LL | extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
20-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21-
|
22-

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use core::intrinsics::mir::*;
1212
#[custom_mir(dialect = "runtime", phase = "optimized")]
1313
#[inline(always)]
1414
pub fn f(a: u32) -> u32 {
15+
//~^ ERROR broken MIR in Item
16+
//~| ERROR encountered critical edge in `Call` terminator
1517
mir! {
1618
{
1719
match a {
@@ -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)