Test lifetimes after types after consts forbidden
Added more complex test and changed error message
This commit is contained in:
parent
f8588284af
commit
b8352eb2d1
6 changed files with 47 additions and 10 deletions
|
@ -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(),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
28
src/test/ui/const-generics/defaults/complex-unord-param.rs
Normal file
28
src/test/ui/const-generics/defaults/complex-unord-param.rs
Normal file
|
@ -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,
|
||||
};
|
||||
}
|
|
@ -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() {}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue