Put MIR checks for loops behind the feature flag

This commit is contained in:
Dylan MacKenzie 2019-12-10 12:42:50 -08:00
parent 57959b2bdc
commit 8f59902aad
2 changed files with 7 additions and 1 deletions

View File

@ -170,6 +170,10 @@ impl NonConstOp for LiveDrop {
#[derive(Debug)] #[derive(Debug)]
pub struct Loop; pub struct Loop;
impl NonConstOp for Loop { impl NonConstOp for Loop {
fn feature_gate(tcx: TyCtxt<'_>) -> Option<bool> {
Some(tcx.features().const_loop)
}
fn emit_error(&self, item: &Item<'_, '_>, span: Span) { fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
// This should be caught by the HIR const-checker. // This should be caught by the HIR const-checker.
item.tcx.sess.delay_span_bug( item.tcx.sess.delay_span_bug(

View File

@ -390,8 +390,10 @@ fn check_terminator(
cleanup: _, cleanup: _,
} => check_operand(tcx, cond, span, def_id, body), } => check_operand(tcx, cond, span, def_id, body),
TerminatorKind::FalseUnwind { .. } => { TerminatorKind::FalseUnwind { .. } if !tcx.features().const_loop => {
Err((span, "loops are not allowed in const fn".into())) Err((span, "loops are not allowed in const fn".into()))
}, },
TerminatorKind::FalseUnwind { .. } => Ok(()),
} }
} }