diff options
| author | kadmin <julianknodt@gmail.com> | 2020-07-30 20:53:32 +0000 |
|---|---|---|
| committer | kadmin <julianknodt@gmail.com> | 2020-08-09 07:41:24 +0000 |
| commit | b8352eb2d19b08606fb407def7a378cc93b8f5de (patch) | |
| tree | 5e3e735fd29c3c503d8fb8a4c74102bcd8d2bf41 | |
| parent | f8588284afbaa7dbe479320d0aeae063f0fd4868 (diff) | |
| download | rust-b8352eb2d19b08606fb407def7a378cc93b8f5de.tar.gz rust-b8352eb2d19b08606fb407def7a378cc93b8f5de.zip | |
Test lifetimes after types after consts forbidden
Added more complex test and changed error message
6 files changed, 47 insertions, 10 deletions
diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs index 4ebf089c68b..f348d9902b3 100644 --- a/src/librustc_ast_passes/ast_validation.rs +++ b/src/librustc_ast_passes/ast_validation.rs @@ -780,13 +780,13 @@ fn validate_generic_param_order<'a>( err.span_suggestion( span, &format!( - "reorder the parameters: lifetimes, then types{}", - if sess.features_untracked().const_generics - || sess.features_untracked().min_const_generics - { - ", then consts" + "reorder the parameters: lifetimes{}", + if sess.features_untracked().const_generics { + ", then consts and types" + } else if sess.features_untracked().min_const_generics { + ", then consts, then types" } else { - "" + ", then types" }, ), ordered_params.clone(), diff --git a/src/test/ui/const-generics/argument_order.stderr b/src/test/ui/const-generics/argument_order.stderr index 058cc346d1b..87dff170b2a 100644 --- a/src/test/ui/const-generics/argument_order.stderr +++ b/src/test/ui/const-generics/argument_order.stderr @@ -2,7 +2,7 @@ error: lifetime parameters must be declared prior to const parameters --> $DIR/argument_order.rs:9:32 | LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> { - | -----------------^^-----^^-------------------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, 'b, T, U, const N: usize, const M: usize>` + | -----------------^^-----^^-------------------- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T, U, const N: usize, const M: usize>` error[E0747]: lifetime provided when a type was expected --> $DIR/argument_order.rs:16:23 diff --git a/src/test/ui/const-generics/const-param-before-other-params.stderr b/src/test/ui/const-generics/const-param-before-other-params.stderr index 5c1171aae60..1194dd30f61 100644 --- a/src/test/ui/const-generics/const-param-before-other-params.stderr +++ b/src/test/ui/const-generics/const-param-before-other-params.stderr @@ -2,7 +2,7 @@ error: lifetime parameters must be declared prior to const parameters --> $DIR/const-param-before-other-params.rs:4:21 | LL | fn bar<const X: (), 'a>(_: &'a ()) { - | --------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const X: ()>` + | --------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const X: ()>` error: aborting due to previous error diff --git a/src/test/ui/const-generics/defaults/complex-unord-param.rs b/src/test/ui/const-generics/defaults/complex-unord-param.rs new file mode 100644 index 00000000000..8ee5604633e --- /dev/null +++ b/src/test/ui/const-generics/defaults/complex-unord-param.rs @@ -0,0 +1,28 @@ +// run-pass +// Checks a complicated usage of unordered params + +#![feature(const_generics)] +#![allow(incomplete_features)] +#![allow(dead_code)] + +struct FixedOutput<'a, const N: usize, T=u32> { + out: &'a [T; N], +} + +trait FixedOutputter { + fn out(&self) -> FixedOutput<'_, 10>; +} + +struct NestedArrays<'a, const N: usize, A: 'a, const M: usize, T:'a =u32> { + args: &'a [&'a [T; M]; N], + specifier: A, +} + +fn main() { + let array = [1, 2, 3]; + let nest = [&array]; + let _ = NestedArrays { + args: &nest, + specifier: true, + }; +} diff --git a/src/test/ui/const-generics/defaults/intermixed-lifetime.rs b/src/test/ui/const-generics/defaults/intermixed-lifetime.rs index ff052edcec7..d53958c9573 100644 --- a/src/test/ui/const-generics/defaults/intermixed-lifetime.rs +++ b/src/test/ui/const-generics/defaults/intermixed-lifetime.rs @@ -6,4 +6,7 @@ struct Foo<const N: usize, 'a, T = u32>(&'a (), T); //~^ Error lifetime parameters must be declared prior to const parameters +struct Bar<const N: usize, T = u32, 'a>(&'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 index 0880581ec7f..d8450ba442d 100644 --- a/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr +++ b/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr @@ -2,7 +2,13 @@ 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>` + | -----------------^^---------- help: reorder the parameters: lifetimes, then consts and types: `<'a, T, const N: usize>` -error: aborting due to previous error +error: lifetime parameters must be declared prior to const parameters + --> $DIR/intermixed-lifetime.rs:9:37 + | +LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T); + | --------------------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, T, const N: usize>` + +error: aborting due to 2 previous errors |
