From bd8a6d79116bdefde629c22693cdd8e87ad7cc72 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Wed, 29 Apr 2020 10:29:04 -0700 Subject: [PATCH] Allow `Downcast` projections unconditionally --- src/librustc_mir/transform/check_consts/ops.rs | 9 --------- src/librustc_mir/transform/check_consts/validation.rs | 5 +---- src/librustc_mir/transform/qualify_min_const_fn.rs | 6 +----- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/librustc_mir/transform/check_consts/ops.rs b/src/librustc_mir/transform/check_consts/ops.rs index 60eb51f7cca..fe20ceb47ee 100644 --- a/src/librustc_mir/transform/check_consts/ops.rs +++ b/src/librustc_mir/transform/check_consts/ops.rs @@ -53,15 +53,6 @@ pub trait NonConstOp: std::fmt::Debug { } } -/// A `Downcast` projection. -#[derive(Debug)] -pub struct Downcast; -impl NonConstOp for Downcast { - fn feature_gate() -> Option { - Some(sym::const_if_match) - } -} - /// A function call where the callee is a pointer. #[derive(Debug)] pub struct FnCallIndirect; diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index b87429199ec..8acfc0fb291 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -448,6 +448,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> { } ProjectionElem::ConstantIndex { .. } + | ProjectionElem::Downcast(..) | ProjectionElem::Subslice { .. } | ProjectionElem::Field(..) | ProjectionElem::Index(_) => { @@ -460,10 +461,6 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> { _ => {} } } - - ProjectionElem::Downcast(..) => { - self.check_op(ops::Downcast); - } } } diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index a7217369bab..cde06cbf84f 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -286,11 +286,6 @@ fn check_place( while let &[ref proj_base @ .., elem] = cursor { cursor = proj_base; match elem { - ProjectionElem::Downcast(..) if !feature_allowed(tcx, def_id, sym::const_if_match) => { - return Err((span, "`match` or `if let` in `const fn` is unstable".into())); - } - ProjectionElem::Downcast(_symbol, _variant_index) => {} - ProjectionElem::Field(..) => { let base_ty = Place::ty_from(place.local, &proj_base, body, tcx).ty; if let Some(def) = base_ty.ty_adt_def() { @@ -303,6 +298,7 @@ fn check_place( } } ProjectionElem::ConstantIndex { .. } + | ProjectionElem::Downcast(..) | ProjectionElem::Subslice { .. } | ProjectionElem::Deref | ProjectionElem::Index(_) => {}