From 752776699357be34e7819ffb235438df7ccf1a9a Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Sun, 10 Nov 2019 10:39:27 -0800 Subject: [PATCH] Move `delay_span_bug` into `emit_error` for if/loop --- .../transform/check_consts/ops.rs | 20 ++++++++++++++++-- .../transform/check_consts/validation.rs | 21 ++++--------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/librustc_mir/transform/check_consts/ops.rs b/src/librustc_mir/transform/check_consts/ops.rs index 303c3984f7c..80f2925193a 100644 --- a/src/librustc_mir/transform/check_consts/ops.rs +++ b/src/librustc_mir/transform/check_consts/ops.rs @@ -138,7 +138,15 @@ fn emit_error(&self, item: &Item<'_, '_>, span: Span) { #[derive(Debug)] pub struct IfOrMatch; -impl NonConstOp for IfOrMatch {} +impl NonConstOp for IfOrMatch { + fn emit_error(&self, item: &Item<'_, '_>, span: Span) { + // This should be caught by the HIR const-checker. + item.tcx.sess.delay_span_bug( + span, + "complex control flow is forbidden in a const context", + ); + } +} #[derive(Debug)] pub struct LiveDrop; @@ -154,7 +162,15 @@ fn emit_error(&self, item: &Item<'_, '_>, span: Span) { #[derive(Debug)] pub struct Loop; -impl NonConstOp for Loop {} +impl NonConstOp for Loop { + fn emit_error(&self, item: &Item<'_, '_>, span: Span) { + // This should be caught by the HIR const-checker. + item.tcx.sess.delay_span_bug( + span, + "complex control flow is forbidden in a const context", + ); + } +} #[derive(Debug)] pub struct MutBorrow(pub BorrowKind); diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index 6687618b748..52481a89e2f 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -245,16 +245,10 @@ pub fn check_body(&mut self) { check_short_circuiting_in_const_local(self.item); - // FIXME: give a span for the loop if body.is_cfg_cyclic() { - // FIXME: make this the `emit_error` impl of `ops::Loop` once the const - // checker is no longer run in compatability mode. - if !self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you { - self.tcx.sess.delay_span_bug( - self.span, - "complex control flow is forbidden in a const context", - ); - } + // We can't provide a good span for the error here, but this should be caught by the + // HIR const-checker anyways. + self.check_op_spanned(ops::Loop, body.span); } self.visit_body(body); @@ -565,14 +559,7 @@ fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) { self.super_statement(statement, location); } StatementKind::FakeRead(FakeReadCause::ForMatchedPlace, _) => { - // FIXME: make this the `emit_error` impl of `ops::IfOrMatch` once the const - // checker is no longer run in compatability mode. - if !self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you { - self.tcx.sess.delay_span_bug( - self.span, - "complex control flow is forbidden in a const context", - ); - } + self.check_op(ops::IfOrMatch); } // FIXME(eddyb) should these really do nothing? StatementKind::FakeRead(..) | -- 2.44.0