Stop checking for while and loop in a const context

This commit is contained in:
Dylan MacKenzie 2020-06-25 17:41:32 -07:00
parent 5bed94cda4
commit 7c46e42512
3 changed files with 6 additions and 26 deletions

View File

@ -164,19 +164,6 @@ fn emit_error(&self, ccx: &ConstCx<'_, '_>, span: Span) {
}
}
#[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 {

View File

@ -207,12 +207,6 @@ pub fn check_body(&mut self) {
}
}
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`.

View File

@ -40,18 +40,17 @@ fn required_feature_gates(self) -> Option<&'static [Symbol]> {
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)