Skip to content

Commit 7527766

Browse files
Move delay_span_bug into emit_error for if/loop
1 parent 6d4e204 commit 7527766

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

src/librustc_mir/transform/check_consts/ops.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,15 @@ impl NonConstOp for HeapAllocation {
138138

139139
#[derive(Debug)]
140140
pub struct IfOrMatch;
141-
impl NonConstOp for IfOrMatch {}
141+
impl NonConstOp for IfOrMatch {
142+
fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
143+
// This should be caught by the HIR const-checker.
144+
item.tcx.sess.delay_span_bug(
145+
span,
146+
"complex control flow is forbidden in a const context",
147+
);
148+
}
149+
}
142150

143151
#[derive(Debug)]
144152
pub struct LiveDrop;
@@ -154,7 +162,15 @@ impl NonConstOp for LiveDrop {
154162

155163
#[derive(Debug)]
156164
pub struct Loop;
157-
impl NonConstOp for Loop {}
165+
impl NonConstOp for Loop {
166+
fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
167+
// This should be caught by the HIR const-checker.
168+
item.tcx.sess.delay_span_bug(
169+
span,
170+
"complex control flow is forbidden in a const context",
171+
);
172+
}
173+
}
158174

159175
#[derive(Debug)]
160176
pub struct MutBorrow(pub BorrowKind);

src/librustc_mir/transform/check_consts/validation.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,10 @@ impl Validator<'a, 'mir, 'tcx> {
245245

246246
check_short_circuiting_in_const_local(self.item);
247247

248-
// FIXME: give a span for the loop
249248
if body.is_cfg_cyclic() {
250-
// FIXME: make this the `emit_error` impl of `ops::Loop` once the const
251-
// checker is no longer run in compatability mode.
252-
if !self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
253-
self.tcx.sess.delay_span_bug(
254-
self.span,
255-
"complex control flow is forbidden in a const context",
256-
);
257-
}
249+
// We can't provide a good span for the error here, but this should be caught by the
250+
// HIR const-checker anyways.
251+
self.check_op_spanned(ops::Loop, body.span);
258252
}
259253

260254
self.visit_body(body);
@@ -565,14 +559,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
565559
self.super_statement(statement, location);
566560
}
567561
StatementKind::FakeRead(FakeReadCause::ForMatchedPlace, _) => {
568-
// FIXME: make this the `emit_error` impl of `ops::IfOrMatch` once the const
569-
// checker is no longer run in compatability mode.
570-
if !self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
571-
self.tcx.sess.delay_span_bug(
572-
self.span,
573-
"complex control flow is forbidden in a const context",
574-
);
575-
}
562+
self.check_op(ops::IfOrMatch);
576563
}
577564
// FIXME(eddyb) should these really do nothing?
578565
StatementKind::FakeRead(..) |

0 commit comments

Comments
 (0)