From 289e5fca7ecdb03db97be9d89ae908f253a3f263 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Tue, 28 Jul 2020 15:55:42 +0200 Subject: forbid generic params in complex consts --- .../min_const_generics/complex-expression.rs | 37 +++++++++++++++++++ .../min_const_generics/complex-expression.stderr | 42 ++++++++++++++++++++++ .../feature-gate-min_const_generics.rs | 4 +++ .../feature-gate-min_const_generics.stderr | 12 +++++++ 4 files changed, 95 insertions(+) create mode 100644 src/test/ui/const-generics/min_const_generics/complex-expression.rs create mode 100644 src/test/ui/const-generics/min_const_generics/complex-expression.stderr create mode 100644 src/test/ui/const-generics/min_const_generics/feature-gate-min_const_generics.rs create mode 100644 src/test/ui/const-generics/min_const_generics/feature-gate-min_const_generics.stderr (limited to 'src/test') 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() {} + +fn ok() -> [u8; M] { + [0; { M }] +} + +struct Break0([u8; { N + 1 }]); +//~^ ERROR generic parameters must not be used inside of non trivial constant values + +struct Break1([u8; { { N } }]); +//~^ ERROR generic parameters must not be used inside of non trivial constant values + +fn break2() { + let _: [u8; N + 1]; + //~^ ERROR generic parameters must not be used inside of non trivial constant values +} + +fn break3() { + let _ = [0; N + 1]; + //~^ ERROR generic parameters must not be used inside of non trivial constant values +} + +trait Foo { + const ASSOC: usize; +} + +impl 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([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([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() {} +//~^ 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() {} + | ^ + | + = note: see issue #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`. -- cgit 1.4.1-3-g733a5