about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2021-04-19 10:15:56 +0200
committerRalf Jung <post@ralfj.de>2021-04-19 10:25:31 +0200
commit04db4abbfceb39374ff21ccce563791c3112a153 (patch)
tree9150ce7c1a123a4b528a7016b79585151bb6ab2b
parentbd9556956ade485ae540fa6b25d2d2b1b2e8b958 (diff)
downloadrust-04db4abbfceb39374ff21ccce563791c3112a153.tar.gz
rust-04db4abbfceb39374ff21ccce563791c3112a153.zip
add gate tests and pacify tidy
-rw-r--r--compiler/rustc_feature/src/active.rs12
-rw-r--r--compiler/rustc_mir/src/transform/check_consts/ops.rs2
-rw-r--r--src/test/ui/consts/const_fn_trait_bound.gated.stderr8
-rw-r--r--src/test/ui/consts/const_fn_trait_bound.rs17
-rw-r--r--src/test/ui/consts/const_fn_trait_bound.stock.stderr30
-rw-r--r--src/test/ui/consts/const_fn_unsize.gated.stderr8
-rw-r--r--src/test/ui/consts/const_fn_unsize.rs16
-rw-r--r--src/test/ui/consts/const_fn_unsize.stock.stderr12
8 files changed, 98 insertions, 7 deletions
diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs
index 590d16e9a5d..74e5a4e26e8 100644
--- a/compiler/rustc_feature/src/active.rs
+++ b/compiler/rustc_feature/src/active.rs
@@ -576,12 +576,6 @@ declare_features! (
     /// Allows using and casting function pointers in a `const fn`.
     (active, const_fn_fn_ptr_basics, "1.48.0", Some(57563), None),
 
-    /// Allows trait bounds in `const fn`.
-    (active, const_fn_trait_bound, "1.53.0", Some(57563), None),
-
-    /// Allows unsizing coercions in `const fn`.
-    (active, const_fn_unsize, "1.53.0", Some(64992), None),
-
     /// Allows to use the `#[cmse_nonsecure_entry]` attribute.
     (active, cmse_nonsecure_entry, "1.48.0", Some(75835), None),
 
@@ -651,6 +645,12 @@ declare_features! (
     /// Allows `extern "wasm" fn`
     (active, wasm_abi, "1.53.0", Some(83788), None),
 
+    /// Allows trait bounds in `const fn`.
+    (active, const_fn_trait_bound, "1.53.0", Some(57563), None),
+
+    /// Allows unsizing coercions in `const fn`.
+    (active, const_fn_unsize, "1.53.0", Some(64992), None),
+
     // -------------------------------------------------------------------------
     // feature-group-end: actual feature gates
     // -------------------------------------------------------------------------
diff --git a/compiler/rustc_mir/src/transform/check_consts/ops.rs b/compiler/rustc_mir/src/transform/check_consts/ops.rs
index 0aa342f0efb..ffeaaf60a30 100644
--- a/compiler/rustc_mir/src/transform/check_consts/ops.rs
+++ b/compiler/rustc_mir/src/transform/check_consts/ops.rs
@@ -552,7 +552,7 @@ impl NonConstOp for UnsizingCast {
             &ccx.tcx.sess.parse_sess,
             sym::const_fn_unsize,
             span,
-            "unsizing casts to types besides slices are not allowed in const fn"
+            "unsizing casts to types besides slices are not allowed in const fn",
         )
     }
 }
diff --git a/src/test/ui/consts/const_fn_trait_bound.gated.stderr b/src/test/ui/consts/const_fn_trait_bound.gated.stderr
new file mode 100644
index 00000000000..ded05cb17c5
--- /dev/null
+++ b/src/test/ui/consts/const_fn_trait_bound.gated.stderr
@@ -0,0 +1,8 @@
+error: fatal error triggered by #[rustc_error]
+  --> $DIR/const_fn_trait_bound.rs:17:1
+   |
+LL | fn main() {}
+   | ^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/consts/const_fn_trait_bound.rs b/src/test/ui/consts/const_fn_trait_bound.rs
new file mode 100644
index 00000000000..b1ef820d827
--- /dev/null
+++ b/src/test/ui/consts/const_fn_trait_bound.rs
@@ -0,0 +1,17 @@
+// gate-test-const_fn_trait_bound
+
+// revisions: stock gated
+
+#![feature(rustc_attrs)]
+#![cfg_attr(gated, feature(const_fn_trait_bound))]
+
+const fn test1<T: std::ops::Add>() {}
+//[stock]~^ trait bounds
+const fn test2(_x: &dyn Send) {}
+//[stock]~^ trait bounds
+const fn test3() -> &'static dyn Send { loop {} }
+//[stock]~^ trait bounds
+
+
+#[rustc_error]
+fn main() {} //[gated]~ fatal error triggered by #[rustc_error]
diff --git a/src/test/ui/consts/const_fn_trait_bound.stock.stderr b/src/test/ui/consts/const_fn_trait_bound.stock.stderr
new file mode 100644
index 00000000000..2ad45f3afde
--- /dev/null
+++ b/src/test/ui/consts/const_fn_trait_bound.stock.stderr
@@ -0,0 +1,30 @@
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
+  --> $DIR/const_fn_trait_bound.rs:8:16
+   |
+LL | const fn test1<T: std::ops::Add>() {}
+   |                ^
+   |
+   = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
+   = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
+
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
+  --> $DIR/const_fn_trait_bound.rs:10:16
+   |
+LL | const fn test2(_x: &dyn Send) {}
+   |                ^^
+   |
+   = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
+   = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
+
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
+  --> $DIR/const_fn_trait_bound.rs:12:21
+   |
+LL | const fn test3() -> &'static dyn Send { loop {} }
+   |                     ^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
+   = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/consts/const_fn_unsize.gated.stderr b/src/test/ui/consts/const_fn_unsize.gated.stderr
new file mode 100644
index 00000000000..8a65c274ca9
--- /dev/null
+++ b/src/test/ui/consts/const_fn_unsize.gated.stderr
@@ -0,0 +1,8 @@
+error: fatal error triggered by #[rustc_error]
+  --> $DIR/const_fn_unsize.rs:16:1
+   |
+LL | fn main() {}
+   | ^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/consts/const_fn_unsize.rs b/src/test/ui/consts/const_fn_unsize.rs
new file mode 100644
index 00000000000..0cab3b0a031
--- /dev/null
+++ b/src/test/ui/consts/const_fn_unsize.rs
@@ -0,0 +1,16 @@
+// gate-test-const_fn_unsize
+
+// revisions: stock gated
+
+#![feature(rustc_attrs)]
+#![cfg_attr(gated, feature(const_fn_unsize))]
+
+use std::ptr::NonNull;
+
+const fn test() {
+    let _x = NonNull::<[i32; 0]>::dangling() as NonNull<[i32]>;
+    //[stock]~^ unsizing cast
+}
+
+#[rustc_error]
+fn main() {} //[gated]~ fatal error triggered by #[rustc_error]
diff --git a/src/test/ui/consts/const_fn_unsize.stock.stderr b/src/test/ui/consts/const_fn_unsize.stock.stderr
new file mode 100644
index 00000000000..cc746d4f175
--- /dev/null
+++ b/src/test/ui/consts/const_fn_unsize.stock.stderr
@@ -0,0 +1,12 @@
+error[E0658]: unsizing casts to types besides slices are not allowed in const fn
+  --> $DIR/const_fn_unsize.rs:11:14
+   |
+LL |     let _x = NonNull::<[i32; 0]>::dangling() as NonNull<[i32]>;
+   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #64992 <https://github.com/rust-lang/rust/issues/64992> for more information
+   = help: add `#![feature(const_fn_unsize)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.