Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Downcast projections unconditionally in const-checking #71688

Merged
merged 2 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/librustc_mir/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Symbol> {
Some(sym::const_if_match)
}
}

/// A function call where the callee is a pointer.
#[derive(Debug)]
pub struct FnCallIndirect;
Expand Down
5 changes: 1 addition & 4 deletions src/librustc_mir/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
}

ProjectionElem::ConstantIndex { .. }
| ProjectionElem::Downcast(..)
| ProjectionElem::Subslice { .. }
| ProjectionElem::Field(..)
| ProjectionElem::Index(_) => {
Expand All @@ -460,10 +461,6 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
_ => {}
}
}

ProjectionElem::Downcast(..) => {
self.check_op(ops::Downcast);
}
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/librustc_mir/transform/qualify_min_const_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -303,6 +298,7 @@ fn check_place(
}
}
ProjectionElem::ConstantIndex { .. }
| ProjectionElem::Downcast(..)
| ProjectionElem::Subslice { .. }
| ProjectionElem::Deref
| ProjectionElem::Index(_) => {}
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/consts/const-fn-error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const fn f(x: usize) -> usize {
//~| ERROR E0658
//~| ERROR E0080
//~| ERROR E0744
//~| ERROR E0019
sum += i;
}
sum
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/issue-52443.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ fn main() {
//~| ERROR calls in constants are limited to constant functions
//~| ERROR references in constants may only refer to immutable values
//~| ERROR calls in constants are limited to constant functions
//~| ERROR constant contains unimplemented expression type
//~| ERROR evaluation of constant value failed
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,5 @@ fn main() { //[if_match]~ ERROR fatal error triggered by #[rustc_error]
//[stock]~^ ERROR `match` is not allowed in a `const`
if let Some(x) = Some(x) { x } else { 1 }
//[stock]~^ ERROR `if` is not allowed in a `const`
//[stock]~| ERROR constant contains unimplemented expression type
}];
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,6 @@ LL | const MATCH: i32 = match 0 { 1 => 2, _ => 0 };
= note: see issue #49146 <https://github.com/rust-lang/rust/issues/49146> for more information
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0019]: constant contains unimplemented expression type
--> $DIR/feature-gate-const-if-match.rs:114:21
|
LL | if let Some(x) = Some(x) { x } else { 1 }
| ^

error: aborting due to 25 previous errors
error: aborting due to 24 previous errors

Some errors have detailed explanations: E0019, E0658.
For more information about an error, try `rustc --explain E0019`.
For more information about this error, try `rustc --explain E0658`.
2 changes: 0 additions & 2 deletions src/test/ui/or-patterns/feature-gate-const-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ fn main() {
let x = Ok(3);
let Ok(y) | Err(y) = x;
//~^ ERROR or-pattern is not allowed in a `const`
//~| ERROR constant contains unimplemented expression type
//~| ERROR constant contains unimplemented expression type
2
}];
}
17 changes: 2 additions & 15 deletions src/test/ui/or-patterns/feature-gate-const-fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,6 @@ LL | let Ok(y) | Err(y) = x;
= note: see issue #49146 <https://github.com/rust-lang/rust/issues/49146> for more information
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0019]: constant contains unimplemented expression type
--> $DIR/feature-gate-const-fn.rs:31:25
|
LL | let Ok(y) | Err(y) = x;
| ^

error[E0019]: constant contains unimplemented expression type
--> $DIR/feature-gate-const-fn.rs:31:16
|
LL | let Ok(y) | Err(y) = x;
| ^

error: aborting due to 8 previous errors
error: aborting due to 6 previous errors

Some errors have detailed explanations: E0019, E0658.
For more information about an error, try `rustc --explain E0019`.
For more information about this error, try `rustc --explain E0658`.