Skip to content

Commit 04db4ab

Browse files
committedApr 19, 2021
add gate tests and pacify tidy
1 parent bd95569 commit 04db4ab

File tree

8 files changed

+98
-7
lines changed

8 files changed

+98
-7
lines changed
 

‎compiler/rustc_feature/src/active.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -576,12 +576,6 @@ 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-
582-
/// Allows unsizing coercions in `const fn`.
583-
(active, const_fn_unsize, "1.53.0", Some(64992), None),
584-
585579
/// Allows to use the `#[cmse_nonsecure_entry]` attribute.
586580
(active, cmse_nonsecure_entry, "1.48.0", Some(75835), None),
587581

@@ -651,6 +645,12 @@ declare_features! (
651645
/// Allows `extern "wasm" fn`
652646
(active, wasm_abi, "1.53.0", Some(83788), None),
653647

648+
/// Allows trait bounds in `const fn`.
649+
(active, const_fn_trait_bound, "1.53.0", Some(57563), None),
650+
651+
/// Allows unsizing coercions in `const fn`.
652+
(active, const_fn_unsize, "1.53.0", Some(64992), None),
653+
654654
// -------------------------------------------------------------------------
655655
// feature-group-end: actual feature gates
656656
// -------------------------------------------------------------------------

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ impl NonConstOp for UnsizingCast {
552552
&ccx.tcx.sess.parse_sess,
553553
sym::const_fn_unsize,
554554
span,
555-
"unsizing casts to types besides slices are not allowed in const fn"
555+
"unsizing casts to types besides slices are not allowed in const fn",
556556
)
557557
}
558558
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: fatal error triggered by #[rustc_error]
2+
--> $DIR/const_fn_trait_bound.rs:17:1
3+
|
4+
LL | fn main() {}
5+
| ^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// gate-test-const_fn_trait_bound
2+
3+
// revisions: stock gated
4+
5+
#![feature(rustc_attrs)]
6+
#![cfg_attr(gated, feature(const_fn_trait_bound))]
7+
8+
const fn test1<T: std::ops::Add>() {}
9+
//[stock]~^ trait bounds
10+
const fn test2(_x: &dyn Send) {}
11+
//[stock]~^ trait bounds
12+
const fn test3() -> &'static dyn Send { loop {} }
13+
//[stock]~^ trait bounds
14+
15+
16+
#[rustc_error]
17+
fn main() {} //[gated]~ fatal error triggered by #[rustc_error]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
2+
--> $DIR/const_fn_trait_bound.rs:8:16
3+
|
4+
LL | const fn test1<T: std::ops::Add>() {}
5+
| ^
6+
|
7+
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
8+
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
9+
10+
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
11+
--> $DIR/const_fn_trait_bound.rs:10:16
12+
|
13+
LL | const fn test2(_x: &dyn Send) {}
14+
| ^^
15+
|
16+
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
17+
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
18+
19+
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
20+
--> $DIR/const_fn_trait_bound.rs:12:21
21+
|
22+
LL | const fn test3() -> &'static dyn Send { loop {} }
23+
| ^^^^^^^^^^^^^^^^^
24+
|
25+
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
26+
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
27+
28+
error: aborting due to 3 previous errors
29+
30+
For more information about this error, try `rustc --explain E0658`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: fatal error triggered by #[rustc_error]
2+
--> $DIR/const_fn_unsize.rs:16:1
3+
|
4+
LL | fn main() {}
5+
| ^^^^^^^^^
6+
7+
error: aborting due to previous error
8+

‎src/test/ui/consts/const_fn_unsize.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// gate-test-const_fn_unsize
2+
3+
// revisions: stock gated
4+
5+
#![feature(rustc_attrs)]
6+
#![cfg_attr(gated, feature(const_fn_unsize))]
7+
8+
use std::ptr::NonNull;
9+
10+
const fn test() {
11+
let _x = NonNull::<[i32; 0]>::dangling() as NonNull<[i32]>;
12+
//[stock]~^ unsizing cast
13+
}
14+
15+
#[rustc_error]
16+
fn main() {} //[gated]~ fatal error triggered by #[rustc_error]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: unsizing casts to types besides slices are not allowed in const fn
2+
--> $DIR/const_fn_unsize.rs:11:14
3+
|
4+
LL | let _x = NonNull::<[i32; 0]>::dangling() as NonNull<[i32]>;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #64992 <https://github.com/rust-lang/rust/issues/64992> for more information
8+
= help: add `#![feature(const_fn_unsize)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)