Skip to content

Commit fdad6ab

Browse files
committed
move 'trait bounds on const fn' to separate feature gate
1 parent 6765010 commit fdad6ab

File tree

14 files changed

+44
-31
lines changed

14 files changed

+44
-31
lines changed

compiler/rustc_feature/src/active.rs

+3
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@ declare_features! (
576576
/// Allows using and casting function pointers in a `const fn`.
577577
(active, const_fn_fn_ptr_basics, "1.48.0", Some(57563), None),
578578

579+
/// Allows trait bounds in `const fn`.
580+
(active, const_fn_trait_bound, "1.53.0", Some(57563), None),
581+
579582
/// Allows to use the `#[cmse_nonsecure_entry]` attribute.
580583
(active, cmse_nonsecure_entry, "1.48.0", Some(75835), None),
581584

compiler/rustc_mir/src/transform/check_consts/ops.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -642,12 +642,17 @@ pub mod ty {
642642
}
643643

644644
fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
645-
mcf_status_in_item(ccx)
645+
if ccx.const_kind() != hir::ConstContext::ConstFn {
646+
Status::Allowed
647+
} else {
648+
Status::Unstable(sym::const_fn_trait_bound)
649+
}
646650
}
647651

648652
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
649-
mcf_build_error(
650-
ccx,
653+
feature_err(
654+
&ccx.tcx.sess.parse_sess,
655+
sym::const_fn_trait_bound,
651656
span,
652657
"trait bounds other than `Sized` on const fn parameters are unstable",
653658
)

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ symbols! {
382382
const_fn,
383383
const_fn_floating_point_arithmetic,
384384
const_fn_fn_ptr_basics,
385+
const_fn_trait_bound,
385386
const_fn_transmute,
386387
const_fn_union,
387388
const_generic_defaults,

library/alloc/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
#![feature(coerce_unsized)]
9191
#![feature(const_btree_new)]
9292
#![feature(const_fn)]
93+
#![cfg_attr(not(bootstrap), feature(const_fn_trait_bound))]
9394
#![feature(cow_is_borrowed)]
9495
#![feature(const_cow_is_borrowed)]
9596
#![feature(destructuring_assignment)]

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
#![feature(const_impl_trait)]
8787
#![feature(const_fn_floating_point_arithmetic)]
8888
#![feature(const_fn_fn_ptr_basics)]
89+
#![cfg_attr(not(bootstrap), feature(const_fn_trait_bound))]
8990
#![feature(const_option)]
9091
#![feature(const_precise_live_drops)]
9192
#![feature(const_ptr_offset)]

src/test/ui/consts/const-eval/issue-49296.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// issue-49296: Unsafe shenigans in constants can result in missing errors
22

3-
#![feature(const_fn)]
43
#![feature(const_fn_union)]
4+
#![feature(const_fn_trait_bound)]
55

66
const unsafe fn transmute<T: Copy, U: Copy>(t: T) -> U {
77
#[repr(C)]

src/test/ui/consts/const-fn.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
// A very basic test of const fn functionality.
55

6-
#![feature(const_fn, const_indexing)]
6+
#![feature(const_indexing)]
7+
#![feature(const_fn_trait_bound)]
78

89
const fn add(x: u32, y: u32) -> u32 {
910
x + y

src/test/ui/consts/min_const_fn/min_const_fn.stderr

+18-18
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,23 @@ LL | const fn get_mut_sq(&mut self) -> &mut T { &mut self.0 }
130130
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
131131
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
132132

133-
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
133+
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
134134
--> $DIR/min_const_fn.rs:84:16
135135
|
136136
LL | const fn foo11<T: std::fmt::Display>(t: T) -> T { t }
137137
| ^
138138
|
139139
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
140-
= help: add `#![feature(const_fn)]` to the crate attributes to enable
140+
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
141141

142-
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
142+
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
143143
--> $DIR/min_const_fn.rs:86:18
144144
|
145145
LL | const fn foo11_2<T: Send>(t: T) -> T { t }
146146
| ^
147147
|
148148
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
149-
= help: add `#![feature(const_fn)]` to the crate attributes to enable
149+
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
150150

151151
error[E0013]: constant functions cannot refer to statics
152152
--> $DIR/min_const_fn.rs:90:27
@@ -209,41 +209,41 @@ LL | const fn inc(x: &mut i32) { *x += 1 }
209209
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
210210
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
211211

212-
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
212+
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
213213
--> $DIR/min_const_fn.rs:110:6
214214
|
215215
LL | impl<T: std::fmt::Debug> Foo<T> {
216216
| ^
217217
|
218218
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
219-
= help: add `#![feature(const_fn)]` to the crate attributes to enable
219+
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
220220

221-
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
221+
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
222222
--> $DIR/min_const_fn.rs:115:6
223223
|
224224
LL | impl<T: std::fmt::Debug + Sized> Foo<T> {
225225
| ^
226226
|
227227
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
228-
= help: add `#![feature(const_fn)]` to the crate attributes to enable
228+
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
229229

230-
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
230+
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
231231
--> $DIR/min_const_fn.rs:120:6
232232
|
233233
LL | impl<T: Sync + Sized> Foo<T> {
234234
| ^
235235
|
236236
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
237-
= help: add `#![feature(const_fn)]` to the crate attributes to enable
237+
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
238238

239-
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
239+
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
240240
--> $DIR/min_const_fn.rs:126:34
241241
|
242242
LL | const fn no_apit2(_x: AlanTuring<impl std::fmt::Debug>) {}
243243
| ^^^^^^^^^^^^^^^^^^^^
244244
|
245245
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
246-
= help: add `#![feature(const_fn)]` to the crate attributes to enable
246+
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
247247

248248
error[E0493]: destructors cannot be evaluated at compile-time
249249
--> $DIR/min_const_fn.rs:126:19
@@ -253,14 +253,14 @@ LL | const fn no_apit2(_x: AlanTuring<impl std::fmt::Debug>) {}
253253
| |
254254
| constant functions cannot evaluate destructors
255255

256-
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
256+
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
257257
--> $DIR/min_const_fn.rs:129:22
258258
|
259259
LL | const fn no_apit(_x: impl std::fmt::Debug) {}
260260
| ^^^^^^^^^^^^^^^^^^^^
261261
|
262262
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
263-
= help: add `#![feature(const_fn)]` to the crate attributes to enable
263+
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
264264

265265
error[E0493]: destructors cannot be evaluated at compile-time
266266
--> $DIR/min_const_fn.rs:129:18
@@ -270,23 +270,23 @@ LL | const fn no_apit(_x: impl std::fmt::Debug) {}
270270
| |
271271
| constant functions cannot evaluate destructors
272272

273-
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
273+
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
274274
--> $DIR/min_const_fn.rs:132:23
275275
|
276276
LL | const fn no_dyn_trait(_x: &dyn std::fmt::Debug) {}
277277
| ^^
278278
|
279279
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
280-
= help: add `#![feature(const_fn)]` to the crate attributes to enable
280+
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
281281

282-
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
282+
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
283283
--> $DIR/min_const_fn.rs:134:32
284284
|
285285
LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
286286
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
287287
|
288288
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
289-
= help: add `#![feature(const_fn)]` to the crate attributes to enable
289+
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
290290

291291
error[E0723]: unsizing casts to types besides slices are not allowed in const fn
292292
--> $DIR/min_const_fn.rs:134:63

src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
1+
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
22
--> $DIR/min_const_fn_dyn.rs:9:5
33
|
44
LL | x.0.field;
55
| ^^^^^^^^^
66
|
77
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
8-
= help: add `#![feature(const_fn)]` to the crate attributes to enable
8+
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
99

1010
error[E0723]: unsizing casts to types besides slices are not allowed in const fn
1111
--> $DIR/min_const_fn_dyn.rs:12:66
@@ -18,4 +18,5 @@ LL | const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) }
1818

1919
error: aborting due to 2 previous errors
2020

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

src/test/ui/consts/unstable-const-fn-in-libcore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#![stable(feature = "core", since = "1.6.0")]
77
#![feature(rustc_const_unstable)]
88
#![feature(staged_api)]
9-
#![feature(const_fn)]
9+
#![feature(const_fn_trait_bound)]
1010

1111
enum Opt<T> {
1212
Some(T),

src/test/ui/rfc-2632-const-trait-impl/call-generic-method-chain.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
// check-pass
44

5-
#![feature(const_fn)]
65
#![feature(const_trait_impl)]
6+
#![feature(const_fn_trait_bound)]
77
#![allow(incomplete_features)]
88

99
struct S;

src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs

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

3-
#![feature(const_fn)]
43
#![feature(const_trait_impl)]
54
#![feature(const_trait_bound_opt_out)]
5+
#![feature(const_fn_trait_bound)]
66
#![allow(incomplete_features)]
77

88
struct S;

src/test/ui/rfc-2632-const-trait-impl/call-generic-method-pass.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
// check-pass
44

5-
#![feature(const_fn)]
65
#![feature(const_trait_impl)]
6+
#![feature(const_fn_trait_bound)]
77
#![allow(incomplete_features)]
88

99
struct S;

src/test/ui/rfc-2632-const-trait-impl/generic-bound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#![allow(incomplete_features)]
44
#![feature(const_trait_impl)]
5-
#![feature(const_fn)]
5+
#![feature(const_fn_trait_bound)]
66

77
use std::marker::PhantomData;
88

0 commit comments

Comments
 (0)