Skip to content

Commit 70aa781

Browse files
Change control flow error to delay span bug
1 parent 0123cbd commit 70aa781

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/librustc_mir/transform/check_consts/validation.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,14 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
461461
self.super_statement(statement, location);
462462
}
463463
StatementKind::FakeRead(FakeReadCause::ForMatchedPlace, _) => {
464-
self.check_op(ops::IfOrMatch);
464+
// FIXME: make this the `emit_error` impl of `ops::IfOrMatch` once the const
465+
// checker is no longer run in compatability mode.
466+
if !self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
467+
self.tcx.sess.delay_span_bug(
468+
self.span,
469+
"complex control flow is forbidden in a const context",
470+
);
471+
}
465472
}
466473
// FIXME(eddyb) should these really do nothing?
467474
StatementKind::FakeRead(..) |

src/librustc_mir/transform/qualify_consts.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,12 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
723723
bb = target;
724724
}
725725
_ => {
726-
self.not_const(ops::Loop);
727-
validator.check_op(ops::Loop);
726+
if !self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
727+
self.tcx.sess.delay_span_bug(
728+
self.span,
729+
"complex control flow is forbidden in a const context",
730+
);
731+
}
728732
break;
729733
}
730734
}
@@ -1253,7 +1257,12 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
12531257
self.super_statement(statement, location);
12541258
}
12551259
StatementKind::FakeRead(FakeReadCause::ForMatchedPlace, _) => {
1256-
self.not_const(ops::IfOrMatch);
1260+
if !self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
1261+
self.tcx.sess.delay_span_bug(
1262+
self.span,
1263+
"complex control flow is forbidden in a const context",
1264+
);
1265+
}
12571266
}
12581267
// FIXME(eddyb) should these really do nothing?
12591268
StatementKind::FakeRead(..) |

src/librustc_passes/check_const.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ impl fmt::Display for ConstKind {
6060
}
6161

6262
fn check_mod_const_bodies(tcx: TyCtxt<'_>, module_def_id: DefId) {
63-
if tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
64-
return;
65-
}
66-
6763
let mut vis = CheckConstVisitor::new(tcx);
6864
tcx.hir().visit_item_likes_in_module(module_def_id, &mut vis.as_deep_visitor());
6965
}
@@ -93,6 +89,11 @@ impl<'tcx> CheckConstVisitor<'tcx> {
9389

9490
/// Emits an error when an unsupported expression is found in a const context.
9591
fn const_check_violated(&self, bad_op: &str, span: Span) {
92+
if self.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
93+
self.sess.span_warn(span, "skipping const checks");
94+
return;
95+
}
96+
9697
let const_kind = self.const_kind
9798
.expect("`const_check_violated` may only be called inside a const context");
9899

0 commit comments

Comments
 (0)