From 7c46e4251219c25582f26b7838958a04b4b50bc6 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 25 Jun 2020 17:41:32 -0700 Subject: [PATCH] Stop checking for `while` and `loop` in a const context --- src/librustc_mir/transform/check_consts/ops.rs | 13 ------------- .../transform/check_consts/validation.rs | 6 ------ src/librustc_passes/check_const.rs | 13 ++++++------- 3 files changed, 6 insertions(+), 26 deletions(-) diff --git a/src/librustc_mir/transform/check_consts/ops.rs b/src/librustc_mir/transform/check_consts/ops.rs index 814437faa581c..ea025f208e49d 100644 --- a/src/librustc_mir/transform/check_consts/ops.rs +++ b/src/librustc_mir/transform/check_consts/ops.rs @@ -164,19 +164,6 @@ impl NonConstOp for LiveDrop { } } -#[derive(Debug)] -pub struct Loop; -impl NonConstOp for Loop { - fn feature_gate() -> Option { - Some(sym::const_loop) - } - - fn emit_error(&self, ccx: &ConstCx<'_, '_>, span: Span) { - // This should be caught by the HIR const-checker. - ccx.tcx.sess.delay_span_bug(span, "complex control flow is forbidden in a const context"); - } -} - #[derive(Debug)] pub struct CellBorrow; impl NonConstOp for CellBorrow { diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index a10e3ee93722c..ca1f0aecd048a 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -207,12 +207,6 @@ impl Validator<'mir, 'tcx> { } } - if body.is_cfg_cyclic() { - // 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); // Ensure that the end result is `Sync` in a non-thread local `static`. diff --git a/src/librustc_passes/check_const.rs b/src/librustc_passes/check_const.rs index e3bb124e1e573..a385d96d974a4 100644 --- a/src/librustc_passes/check_const.rs +++ b/src/librustc_passes/check_const.rs @@ -40,18 +40,17 @@ impl NonConstExpr { let gates: &[_] = match self { // A `for` loop's desugaring contains a call to `IntoIterator::into_iter`, - // so they are not yet allowed with `#![feature(const_loop)]`. + // so they are not yet allowed. // Likewise, `?` desugars to a call to `Try::into_result`. Self::Loop(ForLoop) | Self::Match(ForLoopDesugar | TryDesugar | AwaitDesugar) => { return None; } - Self::Loop(Loop | While | WhileLet) | Self::Match(WhileDesugar | WhileLetDesugar) => { - &[sym::const_loop] - } - - // All other matches are allowed. - Self::Match(Normal | IfDesugar { .. } | IfLetDesugar { .. }) => &[], + // All other expressions are allowed. + Self::Loop(Loop | While | WhileLet) + | Self::Match( + WhileDesugar | WhileLetDesugar | Normal | IfDesugar { .. } | IfLetDesugar { .. }, + ) => &[], }; Some(gates)