]> git.lizzy.rs Git - rust.git/commitdiff
Add various `min_const_generics` regression tests
authorvarkor <github@varkor.com>
Fri, 2 Oct 2020 01:21:15 +0000 (02:21 +0100)
committervarkor <github@varkor.com>
Fri, 2 Oct 2020 01:22:01 +0000 (02:22 +0100)
19 files changed:
src/test/ui/const-generics/min_const_generics/const-argument-if-length.rs [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/const-argument-if-length.stderr [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/generic-function-call-in-array-length.rs [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/generic-sum-in-array-length.rs [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/generic-sum-in-array-length.stderr [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/intrinsics-type_name-as-const-argument.rs [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/intrinsics-type_name-as-const-argument.stderr [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/issue-67375.rs [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/issue-67375.stderr [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/issue-67945-1.rs [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/issue-67945-1.stderr [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/issue-67945-2.rs [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/issue-67945-2.stderr [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/issue-67945-3.rs [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/issue-67945-3.stderr [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/static-reference-array-const-param.rs [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/static-reference-array-const-param.stderr [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/transmute-const-param-static-reference.rs [new file with mode: 0644]
src/test/ui/const-generics/min_const_generics/transmute-const-param-static-reference.stderr [new file with mode: 0644]

diff --git a/src/test/ui/const-generics/min_const_generics/const-argument-if-length.rs b/src/test/ui/const-generics/min_const_generics/const-argument-if-length.rs
new file mode 100644 (file)
index 0000000..354630a
--- /dev/null
@@ -0,0 +1,18 @@
+#![feature(min_const_generics)]
+
+pub const fn is_zst<T: ?Sized>() -> usize {
+    if std::mem::size_of::<T>() == 0 {
+        1
+    } else {
+        0
+    }
+}
+
+pub struct AtLeastByte<T: ?Sized> {
+    value: T,
+    //~^ ERROR the size for values of type `T` cannot be known at compilation time
+    pad: [u8; is_zst::<T>()],
+    //~^ ERROR generic parameters must not be used inside of non trivial constant values
+}
+
+fn main() {}
diff --git a/src/test/ui/const-generics/min_const_generics/const-argument-if-length.stderr b/src/test/ui/const-generics/min_const_generics/const-argument-if-length.stderr
new file mode 100644 (file)
index 0000000..a5bd3ab
--- /dev/null
@@ -0,0 +1,30 @@
+error: generic parameters must not be used inside of non trivial constant values
+  --> $DIR/const-argument-if-length.rs:14:24
+   |
+LL |     pad: [u8; is_zst::<T>()],
+   |                        ^ non-trivial anonymous constants must not depend on the parameter `T`
+   |
+   = note: type parameters are currently not permitted in anonymous constants
+
+error[E0277]: the size for values of type `T` cannot be known at compilation time
+  --> $DIR/const-argument-if-length.rs:12:12
+   |
+LL | pub struct AtLeastByte<T: ?Sized> {
+   |                        - this type parameter needs to be `Sized`
+LL |     value: T,
+   |            ^ doesn't have a size known at compile-time
+   |
+   = note: only the last field of a struct may have a dynamically sized type
+   = help: change the field's type to have a statically known size
+help: borrowed types always have a statically known size
+   |
+LL |     value: &T,
+   |            ^
+help: the `Box` type always has a statically known size and allocates its contents in the heap
+   |
+LL |     value: Box<T>,
+   |            ^^^^ ^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/const-generics/min_const_generics/generic-function-call-in-array-length.rs b/src/test/ui/const-generics/min_const_generics/generic-function-call-in-array-length.rs
new file mode 100644 (file)
index 0000000..c52f402
--- /dev/null
@@ -0,0 +1,11 @@
+#![feature(min_const_generics)]
+
+const fn foo(n: usize) -> usize { n * 2 }
+
+fn bar<const N: usize>() -> [u32; foo(N)] {
+    //~^ ERROR generic parameters must not be used inside of non trivial constant values
+    [0; foo(N)]
+    //~^ ERROR generic parameters must not be used inside of non trivial constant values
+}
+
+fn main() {}
diff --git a/src/test/ui/const-generics/min_const_generics/generic-sum-in-array-length.rs b/src/test/ui/const-generics/min_const_generics/generic-sum-in-array-length.rs
new file mode 100644 (file)
index 0000000..de7e5fe
--- /dev/null
@@ -0,0 +1,7 @@
+#![feature(min_const_generics)]
+
+fn foo<const A: usize, const B: usize>(bar: [usize; A + B]) {}
+//~^ ERROR generic parameters must not be used inside of non trivial constant values
+//~| ERROR generic parameters must not be used inside of non trivial constant values
+
+fn main() {}
diff --git a/src/test/ui/const-generics/min_const_generics/generic-sum-in-array-length.stderr b/src/test/ui/const-generics/min_const_generics/generic-sum-in-array-length.stderr
new file mode 100644 (file)
index 0000000..45d0ba9
--- /dev/null
@@ -0,0 +1,18 @@
+error: generic parameters must not be used inside of non trivial constant values
+  --> $DIR/generic-sum-in-array-length.rs:3:53
+   |
+LL | fn foo<const A: usize, const B: usize>(bar: [usize; A + B]) {}
+   |                                                     ^ non-trivial anonymous constants must not depend on the parameter `A`
+   |
+   = help: it is currently only allowed to use either `A` or `{ A }` as generic constants
+
+error: generic parameters must not be used inside of non trivial constant values
+  --> $DIR/generic-sum-in-array-length.rs:3:57
+   |
+LL | fn foo<const A: usize, const B: usize>(bar: [usize; A + B]) {}
+   |                                                         ^ non-trivial anonymous constants must not depend on the parameter `B`
+   |
+   = help: it is currently only allowed to use either `B` or `{ B }` as generic constants
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/const-generics/min_const_generics/intrinsics-type_name-as-const-argument.rs b/src/test/ui/const-generics/min_const_generics/intrinsics-type_name-as-const-argument.rs
new file mode 100644 (file)
index 0000000..167a3f2
--- /dev/null
@@ -0,0 +1,15 @@
+#![feature(min_const_generics)]
+#![feature(core_intrinsics)]
+
+trait Trait<const S: &'static str> {}
+//~^ ERROR `&'static str` is forbidden as the type of a const generic parameter
+
+struct Bug<T>
+where
+    T: Trait<{std::intrinsics::type_name::<T>()}>
+    //~^ ERROR generic parameters must not be used inside of non trivial constant values
+{
+    t: T
+}
+
+fn main() {}
diff --git a/src/test/ui/const-generics/min_const_generics/intrinsics-type_name-as-const-argument.stderr b/src/test/ui/const-generics/min_const_generics/intrinsics-type_name-as-const-argument.stderr
new file mode 100644 (file)
index 0000000..07147da
--- /dev/null
@@ -0,0 +1,19 @@
+error: generic parameters must not be used inside of non trivial constant values
+  --> $DIR/intrinsics-type_name-as-const-argument.rs:9:44
+   |
+LL |     T: Trait<{std::intrinsics::type_name::<T>()}>
+   |                                            ^ non-trivial anonymous constants must not depend on the parameter `T`
+   |
+   = note: type parameters are currently not permitted in anonymous constants
+
+error: `&'static str` is forbidden as the type of a const generic parameter
+  --> $DIR/intrinsics-type_name-as-const-argument.rs:4:22
+   |
+LL | trait Trait<const S: &'static str> {}
+   |                      ^^^^^^^^^^^^
+   |
+   = note: the only supported types are integers, `bool` and `char`
+   = note: more complex types are supported with `#[feature(const_generics)]`
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/const-generics/min_const_generics/issue-67375.rs b/src/test/ui/const-generics/min_const_generics/issue-67375.rs
new file mode 100644 (file)
index 0000000..77ff100
--- /dev/null
@@ -0,0 +1,9 @@
+#![feature(min_const_generics)]
+
+struct Bug<T> {
+    //~^ ERROR parameter `T` is never used
+    inner: [(); { [|_: &T| {}; 0].len() }],
+    //~^ ERROR generic parameters must not be used inside of non trivial constant values
+}
+
+fn main() {}
diff --git a/src/test/ui/const-generics/min_const_generics/issue-67375.stderr b/src/test/ui/const-generics/min_const_generics/issue-67375.stderr
new file mode 100644 (file)
index 0000000..345bded
--- /dev/null
@@ -0,0 +1,19 @@
+error: generic parameters must not be used inside of non trivial constant values
+  --> $DIR/issue-67375.rs:5:25
+   |
+LL |     inner: [(); { [|_: &T| {}; 0].len() }],
+   |                         ^ non-trivial anonymous constants must not depend on the parameter `T`
+   |
+   = note: type parameters are currently not permitted in anonymous constants
+
+error[E0392]: parameter `T` is never used
+  --> $DIR/issue-67375.rs:3:12
+   |
+LL | struct Bug<T> {
+   |            ^ unused parameter
+   |
+   = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0392`.
diff --git a/src/test/ui/const-generics/min_const_generics/issue-67945-1.rs b/src/test/ui/const-generics/min_const_generics/issue-67945-1.rs
new file mode 100644 (file)
index 0000000..cb1c900
--- /dev/null
@@ -0,0 +1,18 @@
+#![feature(min_const_generics)]
+
+use std::marker::PhantomData;
+
+use std::mem::{self, MaybeUninit};
+
+struct Bug<S> {
+    //~^ ERROR parameter `S` is never used
+    A: [(); {
+        let x: S = MaybeUninit::uninit();
+        //~^ ERROR generic parameters must not be used inside of non trivial constant values
+        let b = &*(&x as *const _ as *const S);
+        //~^ ERROR generic parameters must not be used inside of non trivial constant values
+        0
+    }],
+}
+
+fn main() {}
diff --git a/src/test/ui/const-generics/min_const_generics/issue-67945-1.stderr b/src/test/ui/const-generics/min_const_generics/issue-67945-1.stderr
new file mode 100644 (file)
index 0000000..a9a4fda
--- /dev/null
@@ -0,0 +1,27 @@
+error: generic parameters must not be used inside of non trivial constant values
+  --> $DIR/issue-67945-1.rs:10:16
+   |
+LL |         let x: S = MaybeUninit::uninit();
+   |                ^ non-trivial anonymous constants must not depend on the parameter `S`
+   |
+   = note: type parameters are currently not permitted in anonymous constants
+
+error: generic parameters must not be used inside of non trivial constant values
+  --> $DIR/issue-67945-1.rs:12:45
+   |
+LL |         let b = &*(&x as *const _ as *const S);
+   |                                             ^ non-trivial anonymous constants must not depend on the parameter `S`
+   |
+   = note: type parameters are currently not permitted in anonymous constants
+
+error[E0392]: parameter `S` is never used
+  --> $DIR/issue-67945-1.rs:7:12
+   |
+LL | struct Bug<S> {
+   |            ^ unused parameter
+   |
+   = help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData`
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0392`.
diff --git a/src/test/ui/const-generics/min_const_generics/issue-67945-2.rs b/src/test/ui/const-generics/min_const_generics/issue-67945-2.rs
new file mode 100644 (file)
index 0000000..4b0799d
--- /dev/null
@@ -0,0 +1,16 @@
+#![feature(min_const_generics)]
+
+use std::mem::MaybeUninit;
+
+struct Bug<S> {
+    //~^ ERROR parameter `S` is never used
+    A: [(); {
+        let x: S = MaybeUninit::uninit();
+        //~^ ERROR generic parameters must not be used inside of non trivial constant values
+        let b = &*(&x as *const _ as *const S);
+        //~^ ERROR generic parameters must not be used inside of non trivial constant values
+        0
+    }],
+}
+
+fn main() {}
diff --git a/src/test/ui/const-generics/min_const_generics/issue-67945-2.stderr b/src/test/ui/const-generics/min_const_generics/issue-67945-2.stderr
new file mode 100644 (file)
index 0000000..8c40dc0
--- /dev/null
@@ -0,0 +1,27 @@
+error: generic parameters must not be used inside of non trivial constant values
+  --> $DIR/issue-67945-2.rs:8:16
+   |
+LL |         let x: S = MaybeUninit::uninit();
+   |                ^ non-trivial anonymous constants must not depend on the parameter `S`
+   |
+   = note: type parameters are currently not permitted in anonymous constants
+
+error: generic parameters must not be used inside of non trivial constant values
+  --> $DIR/issue-67945-2.rs:10:45
+   |
+LL |         let b = &*(&x as *const _ as *const S);
+   |                                             ^ non-trivial anonymous constants must not depend on the parameter `S`
+   |
+   = note: type parameters are currently not permitted in anonymous constants
+
+error[E0392]: parameter `S` is never used
+  --> $DIR/issue-67945-2.rs:5:12
+   |
+LL | struct Bug<S> {
+   |            ^ unused parameter
+   |
+   = help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData`
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0392`.
diff --git a/src/test/ui/const-generics/min_const_generics/issue-67945-3.rs b/src/test/ui/const-generics/min_const_generics/issue-67945-3.rs
new file mode 100644 (file)
index 0000000..cde7200
--- /dev/null
@@ -0,0 +1,12 @@
+#![feature(min_const_generics)]
+
+struct Bug<S: ?Sized> {
+    A: [(); {
+        let x: Option<Box<Self>> = None;
+        //~^ ERROR generic `Self` types are currently not permitted in anonymous constants
+        0
+    }],
+    B: S
+}
+
+fn main() {}
diff --git a/src/test/ui/const-generics/min_const_generics/issue-67945-3.stderr b/src/test/ui/const-generics/min_const_generics/issue-67945-3.stderr
new file mode 100644 (file)
index 0000000..c5f9193
--- /dev/null
@@ -0,0 +1,8 @@
+error: generic `Self` types are currently not permitted in anonymous constants
+  --> $DIR/issue-67945-3.rs:5:27
+   |
+LL |         let x: Option<Box<Self>> = None;
+   |                           ^^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/const-generics/min_const_generics/static-reference-array-const-param.rs b/src/test/ui/const-generics/min_const_generics/static-reference-array-const-param.rs
new file mode 100644 (file)
index 0000000..0ef1710
--- /dev/null
@@ -0,0 +1,8 @@
+#![feature(min_const_generics)]
+
+fn a<const X: &'static [u32]>() {}
+//~^ ERROR `&'static [u32]` is forbidden as the type of a const generic parameter
+
+fn main() {
+    a::<{&[]}>();
+}
diff --git a/src/test/ui/const-generics/min_const_generics/static-reference-array-const-param.stderr b/src/test/ui/const-generics/min_const_generics/static-reference-array-const-param.stderr
new file mode 100644 (file)
index 0000000..cc32d8a
--- /dev/null
@@ -0,0 +1,11 @@
+error: `&'static [u32]` is forbidden as the type of a const generic parameter
+  --> $DIR/static-reference-array-const-param.rs:3:15
+   |
+LL | fn a<const X: &'static [u32]>() {}
+   |               ^^^^^^^^^^^^^^
+   |
+   = note: the only supported types are integers, `bool` and `char`
+   = note: more complex types are supported with `#[feature(const_generics)]`
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/const-generics/min_const_generics/transmute-const-param-static-reference.rs b/src/test/ui/const-generics/min_const_generics/transmute-const-param-static-reference.rs
new file mode 100644 (file)
index 0000000..dfa1ece
--- /dev/null
@@ -0,0 +1,12 @@
+#![feature(min_const_generics)]
+
+struct Const<const P: &'static ()>;
+//~^ ERROR `&'static ()` is forbidden as the type of a const generic parameter
+
+fn main() {
+    const A: &'static () = unsafe {
+        std::mem::transmute(10 as *const ())
+    };
+
+    let _ = Const::<{A}>;
+}
diff --git a/src/test/ui/const-generics/min_const_generics/transmute-const-param-static-reference.stderr b/src/test/ui/const-generics/min_const_generics/transmute-const-param-static-reference.stderr
new file mode 100644 (file)
index 0000000..063120a
--- /dev/null
@@ -0,0 +1,11 @@
+error: `&'static ()` is forbidden as the type of a const generic parameter
+  --> $DIR/transmute-const-param-static-reference.rs:3:23
+   |
+LL | struct Const<const P: &'static ()>;
+   |                       ^^^^^^^^^^^
+   |
+   = note: the only supported types are integers, `bool` and `char`
+   = note: more complex types are supported with `#[feature(const_generics)]`
+
+error: aborting due to previous error
+