Skip to content

Commit d2d5b83

Browse files
authored
Rollup merge of rust-lang#67251 - oli-obk:stability_sieve, r=Centril
Require `allow_internal_unstable` for stable min_const_fn using unsta… …ble features r? @Centril cc @ecstatic-morse @RalfJung
2 parents ac0bd42 + 0b1e08a commit d2d5b83

9 files changed

+37
-32
lines changed

src/librustc_mir/transform/qualify_min_const_fn.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span, fn_def_id: DefId) -> Mc
8080
for ty in ty.walk() {
8181
match ty.kind {
8282
ty::Ref(_, _, hir::Mutability::Mutable) => {
83-
if !tcx.features().const_mut_refs {
83+
if !feature_allowed(tcx, fn_def_id, sym::const_mut_refs) {
8484
return Err((
8585
span,
8686
"mutable references in const fn are unstable".into(),
@@ -220,7 +220,7 @@ fn check_statement(
220220
}
221221

222222
| StatementKind::FakeRead(FakeReadCause::ForMatchedPlace, _)
223-
if !tcx.features().const_if_match
223+
if !feature_allowed(tcx, def_id, sym::const_if_match)
224224
=> {
225225
Err((span, "loops and conditional expressions are not stable in const fn".into()))
226226
}
@@ -272,7 +272,7 @@ fn check_place(
272272
while let &[ref proj_base @ .., elem] = cursor {
273273
cursor = proj_base;
274274
match elem {
275-
ProjectionElem::Downcast(..) if !tcx.features().const_if_match
275+
ProjectionElem::Downcast(..) if !feature_allowed(tcx, def_id, sym::const_if_match)
276276
=> return Err((span, "`match` or `if let` in `const fn` is unstable".into())),
277277
ProjectionElem::Downcast(_symbol, _variant_index) => {}
278278

@@ -329,7 +329,7 @@ fn check_terminator(
329329

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

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

346346
| TerminatorKind::Abort | TerminatorKind::Unreachable => {
347347
Err((span, "const fn with unreachable code is not stable".into()))

src/test/ui/consts/const-mut-refs/const_mut_refs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-pass
22

33
#![feature(const_mut_refs)]
4+
#![feature(const_fn)]
45

56
struct Foo {
67
x: usize

src/test/ui/consts/control-flow/basics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#![feature(const_panic)]
66
#![feature(const_if_match)]
7+
#![feature(const_fn)]
78

89
const X: u32 = 4;
910
const Y: u32 = 5;

src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// check-pass
44

55
#![feature(const_if_match)]
6+
#![feature(const_fn)]
67

78
enum E {
89
A,

src/test/ui/consts/control-flow/feature-gate-const-if-match.if_match.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: fatal error triggered by #[rustc_error]
2-
--> $DIR/feature-gate-const-if-match.rs:108:1
2+
--> $DIR/feature-gate-const-if-match.rs:109:1
33
|
44
LL | / fn main() {
55
LL | | let _ = [0; {

src/test/ui/consts/control-flow/feature-gate-const-if-match.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#![feature(rustc_attrs)]
88
#![cfg_attr(if_match, feature(const_if_match))]
9+
#![feature(const_fn)]
910

1011
const _: i32 = if true { //[stock]~ ERROR `if` is not allowed in a `const`
1112
5

src/test/ui/consts/control-flow/feature-gate-const-if-match.stock.stderr

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: `if` is not allowed in a `const`
2-
--> $DIR/feature-gate-const-if-match.rs:10:16
2+
--> $DIR/feature-gate-const-if-match.rs:11:16
33
|
44
LL | const _: i32 = if true {
55
| ________________^
@@ -13,7 +13,7 @@ LL | | };
1313
= help: add `#![feature(const_if_match)]` to the crate attributes to enable
1414

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

231231
error[E0658]: `match` is not allowed in a `const`
232-
--> $DIR/feature-gate-const-if-match.rs:84:24
232+
--> $DIR/feature-gate-const-if-match.rs:85:24
233233
|
234234
LL | const MATCH: i32 = match 0 { 1 => 2, _ => 0 };
235235
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -238,7 +238,7 @@ LL | const MATCH: i32 = match 0 { 1 => 2, _ => 0 };
238238
= help: add `#![feature(const_if_match)]` to the crate attributes to enable
239239

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

src/test/ui/consts/control-flow/short-circuit-let.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#![feature(const_if_match)]
66
#![feature(const_panic)]
7+
#![feature(const_fn)]
78

89
const X: i32 = {
910
let mut x = 0;

src/test/ui/consts/control-flow/single_variant_match_ice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// check-pass
22

3-
#![feature(const_if_match)]
3+
#![feature(const_if_match, const_fn)]
44

55
enum Foo {
66
Prob,

0 commit comments

Comments
 (0)