about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-05-22 17:38:15 +0000
committerbors <bors@rust-lang.org>2021-05-22 17:38:15 +0000
commitf98bd7eeca7f01be426b8ffe73ae6717a9659a82 (patch)
tree3db235399455d1cf28eade2b5927b80da740e628 /src/test
parented20e1e533f70644bc583b3c4e4f85426b98bb4d (diff)
parent5c6f41e349a08e792d7635dc88a6ca9fc51050d3 (diff)
downloadrust-f98bd7eeca7f01be426b8ffe73ae6717a9659a82.tar.gz
rust-f98bd7eeca7f01be426b8ffe73ae6717a9659a82.zip
Auto merge of #85078 - RalfJung:const_fn_unsize, r=oli-obk
stabilize const_fn_unsize

I will post a stabilization report and ask for FCP in https://github.com/rust-lang/rust/issues/64992.
This PR is for the implementation side of stabilization.

r? `@oli-obk`
Fixes https://github.com/rust-lang/rust/issues/64992
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/consts/const_fn_unsize.gated.stderr8
-rw-r--r--src/test/ui/consts/const_fn_unsize.rs23
-rw-r--r--src/test/ui/consts/const_fn_unsize.stock.stderr12
-rw-r--r--src/test/ui/consts/min_const_fn/min_const_fn.rs6
-rw-r--r--src/test/ui/consts/min_const_fn/min_const_fn.stderr34
-rw-r--r--src/test/ui/consts/min_const_fn/min_const_fn_dyn.rs2
-rw-r--r--src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr6
-rw-r--r--src/test/ui/consts/unsizing-cast-non-null.rs10
-rw-r--r--src/test/ui/consts/unsizing-cast-non-null.stderr12
9 files changed, 38 insertions, 75 deletions
diff --git a/src/test/ui/consts/const_fn_unsize.gated.stderr b/src/test/ui/consts/const_fn_unsize.gated.stderr
deleted file mode 100644
index 8a65c274ca9..00000000000
--- a/src/test/ui/consts/const_fn_unsize.gated.stderr
+++ /dev/null
@@ -1,8 +0,0 @@
-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
index 0cab3b0a031..01da57320c2 100644
--- a/src/test/ui/consts/const_fn_unsize.rs
+++ b/src/test/ui/consts/const_fn_unsize.rs
@@ -1,16 +1,21 @@
-// gate-test-const_fn_unsize
-
-// revisions: stock gated
-
-#![feature(rustc_attrs)]
-#![cfg_attr(gated, feature(const_fn_unsize))]
+// run-pass
+#![feature(slice_ptr_len)]
 
 use std::ptr::NonNull;
 
+#[allow(unused)]
 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]
+// Regression test for #75118.
+pub const fn dangling_slice<T>() -> NonNull<[T]> {
+    NonNull::<[T; 1]>::dangling()
+}
+
+const C: NonNull<[i32]> = dangling_slice();
+
+fn main() {
+    assert_eq!(C.as_ptr(), NonNull::<[i32; 1]>::dangling().as_ptr() as *mut _);
+    assert_eq!(C.as_ptr().len(), 1);
+}
diff --git a/src/test/ui/consts/const_fn_unsize.stock.stderr b/src/test/ui/consts/const_fn_unsize.stock.stderr
deleted file mode 100644
index cc746d4f175..00000000000
--- a/src/test/ui/consts/const_fn_unsize.stock.stderr
+++ /dev/null
@@ -1,12 +0,0 @@
-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`.
diff --git a/src/test/ui/consts/min_const_fn/min_const_fn.rs b/src/test/ui/consts/min_const_fn/min_const_fn.rs
index e46127c36bf..b7904e6841b 100644
--- a/src/test/ui/consts/min_const_fn/min_const_fn.rs
+++ b/src/test/ui/consts/min_const_fn/min_const_fn.rs
@@ -133,13 +133,13 @@ const fn no_dyn_trait(_x: &dyn std::fmt::Debug) {}
 //~^ ERROR trait bounds other than `Sized`
 const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
 //~^ ERROR trait bounds other than `Sized`
-//~| ERROR unsizing cast
-//~| ERROR unsizing cast
 
 const fn no_unsafe() { unsafe {} }
 
 const fn really_no_traits_i_mean_it() { (&() as &dyn std::fmt::Debug, ()).1 }
-//~^ ERROR unsizing cast
+//~^ ERROR trait bounds other than `Sized`
+//~| ERROR trait bounds other than `Sized`
+//~| ERROR trait bounds other than `Sized`
 
 const fn no_fn_ptrs(_x: fn()) {}
 //~^ ERROR function pointer
diff --git a/src/test/ui/consts/min_const_fn/min_const_fn.stderr b/src/test/ui/consts/min_const_fn/min_const_fn.stderr
index e6ce7e12520..d31d4121936 100644
--- a/src/test/ui/consts/min_const_fn/min_const_fn.stderr
+++ b/src/test/ui/consts/min_const_fn/min_const_fn.stderr
@@ -288,32 +288,32 @@ LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
    = 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]: unsizing casts to types besides slices are not allowed in const fn
-  --> $DIR/min_const_fn.rs:134:63
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
+  --> $DIR/min_const_fn.rs:139:41
    |
-LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
-   |                                                               ^^^
+LL | const fn really_no_traits_i_mean_it() { (&() as &dyn std::fmt::Debug, ()).1 }
+   |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-   = 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
+   = 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]: unsizing casts to types besides slices are not allowed in const fn
-  --> $DIR/min_const_fn.rs:134:63
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
+  --> $DIR/min_const_fn.rs:139:42
    |
-LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
-   |                                                               ^^^
+LL | const fn really_no_traits_i_mean_it() { (&() as &dyn std::fmt::Debug, ()).1 }
+   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-   = 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
+   = 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]: unsizing casts to types besides slices are not allowed in const fn
-  --> $DIR/min_const_fn.rs:141:42
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
+  --> $DIR/min_const_fn.rs:139:42
    |
 LL | const fn really_no_traits_i_mean_it() { (&() as &dyn std::fmt::Debug, ()).1 }
-   |                                          ^^^
+   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-   = 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
+   = 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]: function pointers cannot appear in constant functions
   --> $DIR/min_const_fn.rs:144:21
diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_dyn.rs b/src/test/ui/consts/min_const_fn/min_const_fn_dyn.rs
index 4a22ef2dffd..6ca1e59b3af 100644
--- a/src/test/ui/consts/min_const_fn/min_const_fn_dyn.rs
+++ b/src/test/ui/consts/min_const_fn/min_const_fn_dyn.rs
@@ -10,6 +10,6 @@ const fn no_inner_dyn_trait2(x: Hide) {
 //~^ ERROR trait bounds other than `Sized`
 }
 const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) }
-//~^ ERROR unsizing cast
+//~^ ERROR trait bounds other than `Sized`
 
 fn main() {}
diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr b/src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr
index cf635d65699..ce844a2f071 100644
--- a/src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr
+++ b/src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr
@@ -7,14 +7,14 @@ LL |     x.0.field;
    = 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]: unsizing casts to types besides slices are not allowed in const fn
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
   --> $DIR/min_const_fn_dyn.rs:12:66
    |
 LL | const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) }
    |                                                                  ^^
    |
-   = 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
+   = 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 2 previous errors
 
diff --git a/src/test/ui/consts/unsizing-cast-non-null.rs b/src/test/ui/consts/unsizing-cast-non-null.rs
deleted file mode 100644
index af6bc2d85fd..00000000000
--- a/src/test/ui/consts/unsizing-cast-non-null.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-// Regression test for #75118.
-
-use std::ptr::NonNull;
-
-pub const fn dangling_slice<T>() -> NonNull<[T]> {
-    NonNull::<[T; 0]>::dangling()
-    //~^ ERROR: unsizing casts to types besides slices
-}
-
-fn main() {}
diff --git a/src/test/ui/consts/unsizing-cast-non-null.stderr b/src/test/ui/consts/unsizing-cast-non-null.stderr
deleted file mode 100644
index 79691cddfb4..00000000000
--- a/src/test/ui/consts/unsizing-cast-non-null.stderr
+++ /dev/null
@@ -1,12 +0,0 @@
-error[E0658]: unsizing casts to types besides slices are not allowed in const fn
-  --> $DIR/unsizing-cast-non-null.rs:6:5
-   |
-LL |     NonNull::<[T; 0]>::dangling()
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = 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`.