about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorBastian Kauschke <bastian_kauschke@hotmail.de>2020-07-28 15:55:42 +0200
committerBastian Kauschke <bastian_kauschke@hotmail.de>2020-08-05 18:30:37 +0200
commit289e5fca7ecdb03db97be9d89ae908f253a3f263 (patch)
treef683ecad6f85cc08a61862c088f4719a2c375f4b /src/test
parent375bccb8b3fa2a517e6e19e24da25cad0413987d (diff)
downloadrust-289e5fca7ecdb03db97be9d89ae908f253a3f263.tar.gz
rust-289e5fca7ecdb03db97be9d89ae908f253a3f263.zip
forbid generic params in complex consts
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/const-generics/min_const_generics/complex-expression.rs37
-rw-r--r--src/test/ui/const-generics/min_const_generics/complex-expression.stderr42
-rw-r--r--src/test/ui/const-generics/min_const_generics/feature-gate-min_const_generics.rs4
-rw-r--r--src/test/ui/const-generics/min_const_generics/feature-gate-min_const_generics.stderr12
4 files changed, 95 insertions, 0 deletions
diff --git a/src/test/ui/const-generics/min_const_generics/complex-expression.rs b/src/test/ui/const-generics/min_const_generics/complex-expression.rs
new file mode 100644
index 00000000000..201af9fcef3
--- /dev/null
+++ b/src/test/ui/const-generics/min_const_generics/complex-expression.rs
@@ -0,0 +1,37 @@
+#![feature(min_const_generics)]
+
+fn test<const N: usize>() {}
+
+fn ok<const M: usize>() -> [u8; M] {
+    [0; { M }]
+}
+
+struct Break0<const N: usize>([u8; { N + 1 }]);
+//~^ ERROR generic parameters must not be used inside of non trivial constant values
+
+struct Break1<const N: usize>([u8; { { N } }]);
+//~^ ERROR generic parameters must not be used inside of non trivial constant values
+
+fn break2<const N: usize>() {
+    let _: [u8; N + 1];
+    //~^ ERROR generic parameters must not be used inside of non trivial constant values
+}
+
+fn break3<const N: usize>() {
+    let _ = [0; N + 1];
+    //~^ ERROR generic parameters must not be used inside of non trivial constant values
+}
+
+trait Foo {
+    const ASSOC: usize;
+}
+
+impl<const N: usize> Foo for [u8; N] {
+    const ASSOC: usize = N + 1;
+    //~^ ERROR generic parameters must not be used inside of non trivial constant values
+    // FIXME(min_const_generics): We probably have to allow this as we can
+    // already allow referencing type parameters here on stable.
+}
+
+
+fn main() {}
diff --git a/src/test/ui/const-generics/min_const_generics/complex-expression.stderr b/src/test/ui/const-generics/min_const_generics/complex-expression.stderr
new file mode 100644
index 00000000000..03857aee076
--- /dev/null
+++ b/src/test/ui/const-generics/min_const_generics/complex-expression.stderr
@@ -0,0 +1,42 @@
+error: generic parameters must not be used inside of non trivial constant values
+  --> $DIR/complex-expression.rs:9:38
+   |
+LL | struct Break0<const N: usize>([u8; { N + 1 }]);
+   |                                      ^ non-trivial anonymous constants must not depend on the parameter `N`
+   |
+   = help: it is currently only allowed to use either `N` or `{ N }` as generic constants
+
+error: generic parameters must not be used inside of non trivial constant values
+  --> $DIR/complex-expression.rs:12:40
+   |
+LL | struct Break1<const N: usize>([u8; { { N } }]);
+   |                                        ^ non-trivial anonymous constants must not depend on the parameter `N`
+   |
+   = help: it is currently only allowed to use either `N` or `{ N }` as generic constants
+
+error: generic parameters must not be used inside of non trivial constant values
+  --> $DIR/complex-expression.rs:16:17
+   |
+LL |     let _: [u8; N + 1];
+   |                 ^ non-trivial anonymous constants must not depend on the parameter `N`
+   |
+   = help: it is currently only allowed to use either `N` or `{ N }` as generic constants
+
+error: generic parameters must not be used inside of non trivial constant values
+  --> $DIR/complex-expression.rs:21:17
+   |
+LL |     let _ = [0; N + 1];
+   |                 ^ non-trivial anonymous constants must not depend on the parameter `N`
+   |
+   = help: it is currently only allowed to use either `N` or `{ N }` as generic constants
+
+error: generic parameters must not be used inside of non trivial constant values
+  --> $DIR/complex-expression.rs:30:26
+   |
+LL |     const ASSOC: usize = N + 1;
+   |                          ^ non-trivial anonymous constants must not depend on the parameter `N`
+   |
+   = help: it is currently only allowed to use either `N` or `{ N }` as generic constants
+
+error: aborting due to 5 previous errors
+
diff --git a/src/test/ui/const-generics/min_const_generics/feature-gate-min_const_generics.rs b/src/test/ui/const-generics/min_const_generics/feature-gate-min_const_generics.rs
new file mode 100644
index 00000000000..423deae4600
--- /dev/null
+++ b/src/test/ui/const-generics/min_const_generics/feature-gate-min_const_generics.rs
@@ -0,0 +1,4 @@
+fn test<const N: usize>() {}
+//~^ ERROR const generics are unstable
+
+fn main() {}
diff --git a/src/test/ui/const-generics/min_const_generics/feature-gate-min_const_generics.stderr b/src/test/ui/const-generics/min_const_generics/feature-gate-min_const_generics.stderr
new file mode 100644
index 00000000000..80cfdc2d28c
--- /dev/null
+++ b/src/test/ui/const-generics/min_const_generics/feature-gate-min_const_generics.stderr
@@ -0,0 +1,12 @@
+error[E0658]: const generics are unstable
+  --> $DIR/feature-gate-min_const_generics.rs:1:15
+   |
+LL | fn test<const N: usize>() {}
+   |               ^
+   |
+   = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
+   = help: add `#![feature(const_generics)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.