Skip to content

Commit

Permalink
Stop checking for while and loop in a const context
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstatic-morse committed Jun 28, 2020
1 parent 5bed94c commit 7c46e42
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 26 deletions.
13 changes: 0 additions & 13 deletions src/librustc_mir/transform/check_consts/ops.rs
Expand Up @@ -164,19 +164,6 @@ impl NonConstOp for LiveDrop {
}
}

#[derive(Debug)]
pub struct Loop;
impl NonConstOp for Loop {
fn feature_gate() -> Option<Symbol> {
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 {
Expand Down
6 changes: 0 additions & 6 deletions src/librustc_mir/transform/check_consts/validation.rs
Expand Up @@ -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`.
Expand Down
13 changes: 6 additions & 7 deletions src/librustc_passes/check_const.rs
Expand Up @@ -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)
Expand Down

0 comments on commit 7c46e42

Please sign in to comment.