Skip to content

Commit 5db5308

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

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
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) {

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)