MIR const-checking

This commit is contained in:
Dylan MacKenzie 2020-05-21 12:46:49 -07:00
parent 48ebd2cdb8
commit 4c2383810b
3 changed files with 1 additions and 33 deletions

View file

@ -142,19 +142,6 @@ impl NonConstOp for HeapAllocation {
}
}
#[derive(Debug)]
pub struct IfOrMatch;
impl NonConstOp for IfOrMatch {
fn feature_gate() -> Option<Symbol> {
Some(sym::const_if_match)
}
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 InlineAsm;
impl NonConstOp for InlineAsm {}

View file

@ -481,21 +481,12 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
self.super_statement(statement, location);
}
StatementKind::FakeRead(
FakeReadCause::ForMatchedPlace
| FakeReadCause::ForMatchGuard
| FakeReadCause::ForGuardBinding,
_,
) => {
self.super_statement(statement, location);
self.check_op(ops::IfOrMatch);
}
StatementKind::LlvmInlineAsm { .. } => {
self.super_statement(statement, location);
self.check_op(ops::InlineAsm);
}
StatementKind::FakeRead(FakeReadCause::ForLet | FakeReadCause::ForIndex, _)
StatementKind::FakeRead(..)
| StatementKind::StorageLive(_)
| StatementKind::StorageDead(_)
| StatementKind::Retag { .. }

View file

@ -239,12 +239,6 @@ fn check_statement(
check_rvalue(tcx, body, def_id, rval, span)
}
StatementKind::FakeRead(FakeReadCause::ForMatchedPlace, _)
if !feature_allowed(tcx, def_id, sym::const_if_match) =>
{
Err((span, "loops and conditional expressions are not stable in const fn".into()))
}
StatementKind::FakeRead(_, place) => check_place(tcx, **place, span, def_id, body),
// just an assignment
@ -355,10 +349,6 @@ fn check_terminator(
check_operand(tcx, value, span, def_id, body)
}
TerminatorKind::SwitchInt { .. } if !feature_allowed(tcx, def_id, sym::const_if_match) => {
Err((span, "loops and conditional expressions are not stable in const fn".into()))
}
TerminatorKind::SwitchInt { discr, switch_ty: _, values: _, targets: _ } => {
check_operand(tcx, discr, span, def_id, body)
}