Skip to content

Require allow_internal_unstable for stable min_const_fn using unsta… #67251

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

Merged
merged 1 commit into from
Dec 13, 2019
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
10 changes: 5 additions & 5 deletions src/librustc_mir/transform/qualify_min_const_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span, fn_def_id: DefId) -> Mc
for ty in ty.walk() {
match ty.kind {
ty::Ref(_, _, hir::Mutability::Mutable) => {
if !tcx.features().const_mut_refs {
if !feature_allowed(tcx, fn_def_id, sym::const_mut_refs) {
return Err((
span,
"mutable references in const fn are unstable".into(),
Expand Down Expand Up @@ -220,7 +220,7 @@ fn check_statement(
}

| StatementKind::FakeRead(FakeReadCause::ForMatchedPlace, _)
if !tcx.features().const_if_match
if !feature_allowed(tcx, def_id, sym::const_if_match)
=> {
Err((span, "loops and conditional expressions are not stable in const fn".into()))
}
Expand Down Expand Up @@ -272,7 +272,7 @@ fn check_place(
while let &[ref proj_base @ .., elem] = cursor {
cursor = proj_base;
match elem {
ProjectionElem::Downcast(..) if !tcx.features().const_if_match
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) => {}

Expand Down Expand Up @@ -329,7 +329,7 @@ fn check_terminator(

| TerminatorKind::FalseEdges { .. }
| TerminatorKind::SwitchInt { .. }
if !tcx.features().const_if_match
if !feature_allowed(tcx, def_id, sym::const_if_match)
=> Err((
span,
"loops and conditional expressions are not stable in const fn".into(),
Expand All @@ -341,7 +341,7 @@ fn check_terminator(
}

// FIXME(ecstaticmorse): We probably want to allow `Unreachable` unconditionally.
TerminatorKind::Unreachable if tcx.features().const_if_match => Ok(()),
TerminatorKind::Unreachable if feature_allowed(tcx, def_id, sym::const_if_match) => Ok(()),

| TerminatorKind::Abort | TerminatorKind::Unreachable => {
Err((span, "const fn with unreachable code is not stable".into()))
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/consts/const-mut-refs/const_mut_refs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// run-pass

#![feature(const_mut_refs)]
#![feature(const_fn)]

struct Foo {
x: usize
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/consts/control-flow/basics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#![feature(const_panic)]
#![feature(const_if_match)]
#![feature(const_fn)]

const X: u32 = 4;
const Y: u32 = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// check-pass

#![feature(const_if_match)]
#![feature(const_fn)]

enum E {
A,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: fatal error triggered by #[rustc_error]
--> $DIR/feature-gate-const-if-match.rs:108:1
--> $DIR/feature-gate-const-if-match.rs:109:1
|
LL | / fn main() {
LL | | let _ = [0; {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#![feature(rustc_attrs)]
#![cfg_attr(if_match, feature(const_if_match))]
#![feature(const_fn)]

const _: i32 = if true { //[stock]~ ERROR `if` is not allowed in a `const`
5
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: `if` is not allowed in a `const`
--> $DIR/feature-gate-const-if-match.rs:10:16
--> $DIR/feature-gate-const-if-match.rs:11:16
|
LL | const _: i32 = if true {
| ________________^
Expand All @@ -13,7 +13,7 @@ LL | | };
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `if` is not allowed in a `const`
--> $DIR/feature-gate-const-if-match.rs:16:16
--> $DIR/feature-gate-const-if-match.rs:17:16
|
LL | const _: i32 = if let Some(true) = Some(false) {
| ________________^
Expand All @@ -27,7 +27,7 @@ LL | | };
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `match` is not allowed in a `const`
--> $DIR/feature-gate-const-if-match.rs:22:16
--> $DIR/feature-gate-const-if-match.rs:23:16
|
LL | const _: i32 = match 1 {
| ________________^
Expand All @@ -41,7 +41,7 @@ LL | | };
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `if` is not allowed in a `static`
--> $DIR/feature-gate-const-if-match.rs:29:13
--> $DIR/feature-gate-const-if-match.rs:30:13
|
LL | let x = if true { 0 } else { 1 };
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -50,7 +50,7 @@ LL | let x = if true { 0 } else { 1 };
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `match` is not allowed in a `static`
--> $DIR/feature-gate-const-if-match.rs:31:13
--> $DIR/feature-gate-const-if-match.rs:32:13
|
LL | let x = match x { 0 => 1, _ => 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -59,7 +59,7 @@ LL | let x = match x { 0 => 1, _ => 0 };
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `if` is not allowed in a `static`
--> $DIR/feature-gate-const-if-match.rs:33:5
--> $DIR/feature-gate-const-if-match.rs:34:5
|
LL | if let Some(x) = Some(x) { x } else { 1 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -68,7 +68,7 @@ LL | if let Some(x) = Some(x) { x } else { 1 }
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `if` is not allowed in a `static mut`
--> $DIR/feature-gate-const-if-match.rs:38:13
--> $DIR/feature-gate-const-if-match.rs:39:13
|
LL | let x = if true { 0 } else { 1 };
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -77,7 +77,7 @@ LL | let x = if true { 0 } else { 1 };
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `match` is not allowed in a `static mut`
--> $DIR/feature-gate-const-if-match.rs:40:13
--> $DIR/feature-gate-const-if-match.rs:41:13
|
LL | let x = match x { 0 => 1, _ => 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -86,7 +86,7 @@ LL | let x = match x { 0 => 1, _ => 0 };
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `if` is not allowed in a `static mut`
--> $DIR/feature-gate-const-if-match.rs:42:5
--> $DIR/feature-gate-const-if-match.rs:43:5
|
LL | if let Some(x) = Some(x) { x } else { 1 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -95,7 +95,7 @@ LL | if let Some(x) = Some(x) { x } else { 1 }
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `if` is not allowed in a `const fn`
--> $DIR/feature-gate-const-if-match.rs:47:5
--> $DIR/feature-gate-const-if-match.rs:48:5
|
LL | if true { 5 } else { 6 }
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -104,7 +104,7 @@ LL | if true { 5 } else { 6 }
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `if` is not allowed in a `const fn`
--> $DIR/feature-gate-const-if-match.rs:51:5
--> $DIR/feature-gate-const-if-match.rs:52:5
|
LL | / if let Some(true) = a {
LL | | 0
Expand All @@ -117,7 +117,7 @@ LL | | }
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `match` is not allowed in a `const fn`
--> $DIR/feature-gate-const-if-match.rs:59:5
--> $DIR/feature-gate-const-if-match.rs:60:5
|
LL | / match i {
LL | | i if i > 10 => i,
Expand All @@ -130,7 +130,7 @@ LL | | }
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `if` is not allowed in a `const fn`
--> $DIR/feature-gate-const-if-match.rs:90:17
--> $DIR/feature-gate-const-if-match.rs:91:17
|
LL | let x = if y { 0 } else { 1 };
| ^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -139,7 +139,7 @@ LL | let x = if y { 0 } else { 1 };
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `match` is not allowed in a `const fn`
--> $DIR/feature-gate-const-if-match.rs:92:17
--> $DIR/feature-gate-const-if-match.rs:93:17
|
LL | let x = match x { 0 => 1, _ => 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -148,7 +148,7 @@ LL | let x = match x { 0 => 1, _ => 0 };
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `if` is not allowed in a `const fn`
--> $DIR/feature-gate-const-if-match.rs:94:9
--> $DIR/feature-gate-const-if-match.rs:95:9
|
LL | if let Some(x) = Some(x) { x } else { 1 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -157,7 +157,7 @@ LL | if let Some(x) = Some(x) { x } else { 1 }
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `if` is not allowed in a `const`
--> $DIR/feature-gate-const-if-match.rs:110:17
--> $DIR/feature-gate-const-if-match.rs:111:17
|
LL | let x = if false { 0 } else { 1 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -166,7 +166,7 @@ LL | let x = if false { 0 } else { 1 };
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `match` is not allowed in a `const`
--> $DIR/feature-gate-const-if-match.rs:112:17
--> $DIR/feature-gate-const-if-match.rs:113:17
|
LL | let x = match x { 0 => 1, _ => 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -175,7 +175,7 @@ LL | let x = match x { 0 => 1, _ => 0 };
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `if` is not allowed in a `const`
--> $DIR/feature-gate-const-if-match.rs:114:9
--> $DIR/feature-gate-const-if-match.rs:115:9
|
LL | if let Some(x) = Some(x) { x } else { 1 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -184,7 +184,7 @@ LL | if let Some(x) = Some(x) { x } else { 1 }
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `if` is not allowed in a `const`
--> $DIR/feature-gate-const-if-match.rs:67:21
--> $DIR/feature-gate-const-if-match.rs:68:21
|
LL | const IF: i32 = if true { 5 } else { 6 };
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -193,7 +193,7 @@ LL | const IF: i32 = if true { 5 } else { 6 };
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `if` is not allowed in a `const`
--> $DIR/feature-gate-const-if-match.rs:70:25
--> $DIR/feature-gate-const-if-match.rs:71:25
|
LL | const IF_LET: i32 = if let Some(true) = None { 5 } else { 6 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -202,7 +202,7 @@ LL | const IF_LET: i32 = if let Some(true) = None { 5 } else { 6 };
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `match` is not allowed in a `const`
--> $DIR/feature-gate-const-if-match.rs:73:24
--> $DIR/feature-gate-const-if-match.rs:74:24
|
LL | const MATCH: i32 = match 0 { 1 => 2, _ => 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -211,7 +211,7 @@ LL | const MATCH: i32 = match 0 { 1 => 2, _ => 0 };
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `if` is not allowed in a `const`
--> $DIR/feature-gate-const-if-match.rs:78:21
--> $DIR/feature-gate-const-if-match.rs:79:21
|
LL | const IF: i32 = if true { 5 } else { 6 };
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -220,7 +220,7 @@ LL | const IF: i32 = if true { 5 } else { 6 };
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `if` is not allowed in a `const`
--> $DIR/feature-gate-const-if-match.rs:81:25
--> $DIR/feature-gate-const-if-match.rs:82:25
|
LL | const IF_LET: i32 = if let Some(true) = None { 5 } else { 6 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -229,7 +229,7 @@ LL | const IF_LET: i32 = if let Some(true) = None { 5 } else { 6 };
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error[E0658]: `match` is not allowed in a `const`
--> $DIR/feature-gate-const-if-match.rs:84:24
--> $DIR/feature-gate-const-if-match.rs:85:24
|
LL | const MATCH: i32 = match 0 { 1 => 2, _ => 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -238,7 +238,7 @@ LL | const MATCH: i32 = match 0 { 1 => 2, _ => 0 };
= 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
--> $DIR/feature-gate-const-if-match.rs:115:21
|
LL | if let Some(x) = Some(x) { x } else { 1 }
| ^
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/consts/control-flow/short-circuit-let.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#![feature(const_if_match)]
#![feature(const_panic)]
#![feature(const_fn)]

const X: i32 = {
let mut x = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// check-pass

#![feature(const_if_match)]
#![feature(const_if_match, const_fn)]

enum Foo {
Prob,
Expand Down