Skip to content

Commit b8352eb

Browse files
committed
Test lifetimes after types after consts forbidden
Added more complex test and changed error message
1 parent f858828 commit b8352eb

File tree

6 files changed

+47
-10
lines changed

6 files changed

+47
-10
lines changed

src/librustc_ast_passes/ast_validation.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -780,13 +780,13 @@ fn validate_generic_param_order<'a>(
780780
err.span_suggestion(
781781
span,
782782
&format!(
783-
"reorder the parameters: lifetimes, then types{}",
784-
if sess.features_untracked().const_generics
785-
|| sess.features_untracked().min_const_generics
786-
{
787-
", then consts"
783+
"reorder the parameters: lifetimes{}",
784+
if sess.features_untracked().const_generics {
785+
", then consts and types"
786+
} else if sess.features_untracked().min_const_generics {
787+
", then consts, then types"
788788
} else {
789-
""
789+
", then types"
790790
},
791791
),
792792
ordered_params.clone(),

src/test/ui/const-generics/argument_order.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: lifetime parameters must be declared prior to const parameters
22
--> $DIR/argument_order.rs:9:32
33
|
44
LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
5-
| -----------------^^-----^^-------------------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, 'b, T, U, const N: usize, const M: usize>`
5+
| -----------------^^-----^^-------------------- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T, U, const N: usize, const M: usize>`
66

77
error[E0747]: lifetime provided when a type was expected
88
--> $DIR/argument_order.rs:16:23

src/test/ui/const-generics/const-param-before-other-params.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: lifetime parameters must be declared prior to const parameters
22
--> $DIR/const-param-before-other-params.rs:4:21
33
|
44
LL | fn bar<const X: (), 'a>(_: &'a ()) {
5-
| --------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const X: ()>`
5+
| --------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const X: ()>`
66

77
error: aborting due to previous error
88

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// run-pass
2+
// Checks a complicated usage of unordered params
3+
4+
#![feature(const_generics)]
5+
#![allow(incomplete_features)]
6+
#![allow(dead_code)]
7+
8+
struct FixedOutput<'a, const N: usize, T=u32> {
9+
out: &'a [T; N],
10+
}
11+
12+
trait FixedOutputter {
13+
fn out(&self) -> FixedOutput<'_, 10>;
14+
}
15+
16+
struct NestedArrays<'a, const N: usize, A: 'a, const M: usize, T:'a =u32> {
17+
args: &'a [&'a [T; M]; N],
18+
specifier: A,
19+
}
20+
21+
fn main() {
22+
let array = [1, 2, 3];
23+
let nest = [&array];
24+
let _ = NestedArrays {
25+
args: &nest,
26+
specifier: true,
27+
};
28+
}

src/test/ui/const-generics/defaults/intermixed-lifetime.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66
struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
77
//~^ Error lifetime parameters must be declared prior to const parameters
88

9+
struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
10+
//~^ Error lifetime parameters must be declared prior to const parameters
11+
912
fn main() {}

src/test/ui/const-generics/defaults/intermixed-lifetime.stderr

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ error: lifetime parameters must be declared prior to const parameters
22
--> $DIR/intermixed-lifetime.rs:6:28
33
|
44
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
5-
| -----------------^^---------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T, const N: usize>`
5+
| -----------------^^---------- help: reorder the parameters: lifetimes, then consts and types: `<'a, T, const N: usize>`
66

7-
error: aborting due to previous error
7+
error: lifetime parameters must be declared prior to const parameters
8+
--> $DIR/intermixed-lifetime.rs:9:37
9+
|
10+
LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
11+
| --------------------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, T, const N: usize>`
12+
13+
error: aborting due to 2 previous errors
814

0 commit comments

Comments
 (0)