diff options
| author | kadmin <julianknodt@gmail.com> | 2020-07-30 18:43:44 +0000 |
|---|---|---|
| committer | kadmin <julianknodt@gmail.com> | 2020-08-09 07:41:22 +0000 |
| commit | f8588284afbaa7dbe479320d0aeae063f0fd4868 (patch) | |
| tree | a6ca20763fbf6d733b5ce09bd083f7159af4549c /src/test/ui/const-generics | |
| parent | 18481cbec981f320abfb83df0e96fd127def7cd5 (diff) | |
| download | rust-f8588284afbaa7dbe479320d0aeae063f0fd4868.tar.gz rust-f8588284afbaa7dbe479320d0aeae063f0fd4868.zip | |
Added +1 test for only works w/ feat const gen
Added this test to ensure that reordering the parameters only works with the feature const generics enabled. Fixed nits Also added another test to verify that intermixed lifetimes are forbidden
Diffstat (limited to 'src/test/ui/const-generics')
6 files changed, 54 insertions, 1 deletions
diff --git a/src/test/ui/const-generics/defaults/intermixed-lifetime.rs b/src/test/ui/const-generics/defaults/intermixed-lifetime.rs new file mode 100644 index 00000000000..ff052edcec7 --- /dev/null +++ b/src/test/ui/const-generics/defaults/intermixed-lifetime.rs @@ -0,0 +1,9 @@ +// Checks that lifetimes cannot be interspersed between consts and types. + +#![feature(const_generics)] +#![allow(incomplete_features)] + +struct Foo<const N: usize, 'a, T = u32>(&'a (), T); +//~^ Error lifetime parameters must be declared prior to const parameters + +fn main() {} diff --git a/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr b/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr new file mode 100644 index 00000000000..0880581ec7f --- /dev/null +++ b/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr @@ -0,0 +1,8 @@ +error: lifetime parameters must be declared prior to const parameters + --> $DIR/intermixed-lifetime.rs:6:28 + | +LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T); + | -----------------^^---------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T, const N: usize>` + +error: aborting due to previous error + diff --git a/src/test/ui/const-generics/defaults/needs-feature.rs b/src/test/ui/const-generics/defaults/needs-feature.rs new file mode 100644 index 00000000000..ea38a4022ae --- /dev/null +++ b/src/test/ui/const-generics/defaults/needs-feature.rs @@ -0,0 +1,8 @@ +// Verifies that having generic parameters after constants is not permitted without the +// `const_generics` feature. + +struct A<const N: usize, T=u32>(T); +//~^ ERROR type parameters must be declared prior +//~| ERROR const generics are unstable + +fn main() {} diff --git a/src/test/ui/const-generics/defaults/needs-feature.stderr b/src/test/ui/const-generics/defaults/needs-feature.stderr new file mode 100644 index 00000000000..30604feab1b --- /dev/null +++ b/src/test/ui/const-generics/defaults/needs-feature.stderr @@ -0,0 +1,18 @@ +error: type parameters must be declared prior to const parameters + --> $DIR/needs-feature.rs:4:26 + | +LL | struct A<const N: usize, T=u32>(T); + | -----------------^----- help: reorder the parameters: lifetimes, then types: `<T, const N: usize>` + +error[E0658]: const generics are unstable + --> $DIR/needs-feature.rs:4:16 + | +LL | struct A<const N: usize, T=u32>(T); + | ^ + | + = 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 2 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/const-generics/defaults/right-order.rs b/src/test/ui/const-generics/defaults/right-order.rs index f1b5c1f02c8..fce3ab2e6a3 100644 --- a/src/test/ui/const-generics/defaults/right-order.rs +++ b/src/test/ui/const-generics/defaults/right-order.rs @@ -1,5 +1,5 @@ // run-pass -// Verifies that having generic parameters after constants is permitted +// Verifies that having generic parameters after constants is permitted. #![feature(const_generics)] #![allow(incomplete_features)] diff --git a/src/test/ui/const-generics/defaults/type-after-const-requires-default.rs b/src/test/ui/const-generics/defaults/type-after-const-requires-default.rs new file mode 100644 index 00000000000..fc977d6617c --- /dev/null +++ b/src/test/ui/const-generics/defaults/type-after-const-requires-default.rs @@ -0,0 +1,10 @@ +// run-pass +// Verifies that having generic parameters after constants is permitted + +#![feature(const_generics)] +#![allow(incomplete_features)] + +#[allow(dead_code)] +struct A<const N: usize, T>(T); + +fn main() {} |
