Suggest correct location for lifetime parameters in use

This commit is contained in:
Esteban Küber 2019-01-12 19:25:03 -08:00
parent db740313e0
commit 28ea03e114
7 changed files with 82 additions and 47 deletions

View file

@ -1,8 +1,17 @@
fn main() {
(0..4)
.map(|x| x * 2)
.collect::<Vec<'a, usize, 'b>>()
//~^ ERROR lifetime parameters must be declared prior to type parameters
//~| ERROR use of undeclared lifetime name
//~| ERROR use of undeclared lifetime name
// can't run rustfix because it doesn't handle multipart suggestions correctly
// compile-flags: -Zborrowck=mir
// we need the above to avoid ast borrowck failure in recovered code
struct S<'a, T> {
a: &'a T,
b: &'a T,
}
fn foo<'a, 'b>(start: &'a usize, end: &'a usize) {
let _x = (*start..*end)
.map(|x| S { a: start, b: end })
.collect::<Vec<S<_, 'a>>>();
//~^ ERROR lifetime parameters must be declared prior to type parameters
}
fn main() {}

View file

@ -1,21 +1,12 @@
error: lifetime parameters must be declared prior to type parameters
--> $DIR/issue-14303-fncall.rs:4:31
--> $DIR/issue-14303-fncall.rs:13:29
|
LL | .collect::<Vec<'a, usize, 'b>>()
| ^^ must be declared prior to type parameters
error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/issue-14303-fncall.rs:4:20
LL | .collect::<Vec<S<_, 'a>>>();
| ^^ must be declared prior to type parameters
help: move the lifetime parameter prior to the first type parameter
|
LL | .collect::<Vec<'a, usize, 'b>>()
| ^^ undeclared lifetime
LL | .collect::<Vec<S<'a, _>>>();
| ^^^ --
error[E0261]: use of undeclared lifetime name `'b`
--> $DIR/issue-14303-fncall.rs:4:31
|
LL | .collect::<Vec<'a, usize, 'b>>()
| ^^ undeclared lifetime
error: aborting due to previous error
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0261`.

View file

@ -9,6 +9,5 @@ mod foo {
fn bar<'a, 'b, 'c, T>(x: foo::X<'a, T, 'b, 'c>) {}
//~^ ERROR lifetime parameters must be declared prior to type parameters
//~| ERROR lifetime parameters must be declared prior to type parameters
fn main() {}

View file

@ -2,13 +2,13 @@ error: lifetime parameters must be declared prior to type parameters
--> $DIR/issue-14303-path.rs:10:40
|
LL | fn bar<'a, 'b, 'c, T>(x: foo::X<'a, T, 'b, 'c>) {}
| ^^ must be declared prior to type parameters
error: lifetime parameters must be declared prior to type parameters
--> $DIR/issue-14303-path.rs:10:44
| ^^ ^^ must be declared prior to type parameters
| |
| must be declared prior to type parameters
help: move the lifetime parameters prior to the first type parameter
|
LL | fn bar<'a, 'b, 'c, T>(x: foo::X<'a, T, 'b, 'c>) {}
| ^^ must be declared prior to type parameters
LL | fn bar<'a, 'b, 'c, T>(x: foo::X<'a, 'b, 'c, T>) {}
| ^^^ ^^^ --
error: aborting due to 2 previous errors
error: aborting due to previous error

View file

@ -1,8 +1,6 @@
// A few contrived examples where lifetime should (or should not) be parsed as an object type.
// Lifetimes parsed as types are still rejected later by semantic checks.
// compile-flags: -Z continue-parse-after-error
struct S<'a, T>(&'a u8, T);
fn main() {

View file

@ -1,29 +1,33 @@
error: lifetime parameters must be declared prior to type parameters
--> $DIR/trait-object-vs-lifetime.rs:16:25
--> $DIR/trait-object-vs-lifetime.rs:14:25
|
LL | let _: S<'static +, 'static>;
| ^^^^^^^ must be declared prior to type parameters
help: move the lifetime parameter prior to the first type parameter
|
LL | let _: S<'static, 'static +>;
| ^^^^^^^^ --
error[E0224]: at least one non-builtin trait is required for an object type
--> $DIR/trait-object-vs-lifetime.rs:11:23
--> $DIR/trait-object-vs-lifetime.rs:9:23
|
LL | let _: S<'static, 'static +>;
| ^^^^^^^^^
error[E0107]: wrong number of lifetime arguments: expected 1, found 2
--> $DIR/trait-object-vs-lifetime.rs:13:23
--> $DIR/trait-object-vs-lifetime.rs:11:23
|
LL | let _: S<'static, 'static>;
| ^^^^^^^ unexpected lifetime argument
error[E0107]: wrong number of type arguments: expected 1, found 0
--> $DIR/trait-object-vs-lifetime.rs:13:12
--> $DIR/trait-object-vs-lifetime.rs:11:12
|
LL | let _: S<'static, 'static>;
| ^^^^^^^^^^^^^^^^^^^ expected 1 type argument
error[E0224]: at least one non-builtin trait is required for an object type
--> $DIR/trait-object-vs-lifetime.rs:16:14
--> $DIR/trait-object-vs-lifetime.rs:14:14
|
LL | let _: S<'static +, 'static>;
| ^^^^^^^^^