Skip to content

Make E0621 missing lifetime suggestion verbose #142042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions compiler/rustc_trait_selection/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,8 @@ pub enum ExplicitLifetimeRequired<'a> {
#[suggestion(
trait_selection_explicit_lifetime_required_sugg_with_ident,
code = "{new_ty}",
applicability = "unspecified"
applicability = "unspecified",
style = "verbose"
)]
new_ty_span: Span,
#[skip_arg]
Expand All @@ -774,7 +775,8 @@ pub enum ExplicitLifetimeRequired<'a> {
#[suggestion(
trait_selection_explicit_lifetime_required_sugg_with_param_type,
code = "{new_ty}",
applicability = "unspecified"
applicability = "unspecified",
style = "verbose"
)]
new_ty_span: Span,
#[skip_arg]
Expand Down Expand Up @@ -1462,7 +1464,8 @@ pub enum SuggestAccessingField<'a> {
#[suggestion(
trait_selection_suggest_accessing_field,
code = "{snippet}.{name}",
applicability = "maybe-incorrect"
applicability = "maybe-incorrect",
style = "verbose"
)]
Safe {
#[primary_span]
Expand All @@ -1474,7 +1477,8 @@ pub enum SuggestAccessingField<'a> {
#[suggestion(
trait_selection_suggest_accessing_field,
code = "unsafe {{ {snippet}.{name} }}",
applicability = "maybe-incorrect"
applicability = "maybe-incorrect",
style = "verbose"
)]
Unsafe {
#[primary_span]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ LL | }
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/without-precise-captures-we-are-powerless.rs:38:5
|
LL | fn through_field_and_ref<'a>(x: &S<'a>) {
| ------ help: add explicit lifetime `'a` to the type of `x`: `&'a S<'a>`
...
LL | outlives::<'a>(call_once(c));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `x`
|
LL | fn through_field_and_ref<'a>(x: &'a S<'a>) {
| ++

error[E0597]: `c` does not live long enough
--> $DIR/without-precise-captures-we-are-powerless.rs:43:20
Expand All @@ -131,11 +133,13 @@ LL | }
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/without-precise-captures-we-are-powerless.rs:44:5
|
LL | fn through_field_and_ref_move<'a>(x: &S<'a>) {
| ------ help: add explicit lifetime `'a` to the type of `x`: `&'a S<'a>`
...
LL | outlives::<'a>(call_once(c));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `x`
|
LL | fn through_field_and_ref_move<'a>(x: &'a S<'a>) {
| ++

error: aborting due to 10 previous errors

Expand Down
9 changes: 6 additions & 3 deletions tests/ui/async-await/issues/issue-63388-1.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
error[E0621]: explicit lifetime required in the type of `foo`
--> $DIR/issue-63388-1.rs:14:9
|
LL | &'a self, foo: &dyn Foo
| -------- help: add explicit lifetime `'a` to the type of `foo`: `&'a (dyn Foo + 'a)`
...
LL | foo
| ^^^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `foo`
|
LL - &'a self, foo: &dyn Foo
LL + &'a self, foo: &'a (dyn Foo + 'a)
|

error: aborting due to 1 previous error

Expand Down
9 changes: 6 additions & 3 deletions tests/ui/impl-trait/must_outlive_least_region_or_bound.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/must_outlive_least_region_or_bound.rs:15:41
|
LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x }
| ---- ^ lifetime `'a` required
| |
| help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
| ^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `x`
|
LL | fn foo<'a>(x: &'a i32) -> impl Copy + 'a { x }
| ++

error: lifetime may not live long enough
--> $DIR/must_outlive_least_region_or_bound.rs:30:55
Expand Down
8 changes: 5 additions & 3 deletions tests/ui/issues/issue-13058.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
error[E0621]: explicit lifetime required in the type of `cont`
--> $DIR/issue-13058.rs:14:21
|
LL | fn check<'r, I: Iterator<Item=usize>, T: Itble<'r, usize, I>>(cont: &T) -> bool
| -- help: add explicit lifetime `'r` to the type of `cont`: `&'r T`
LL | {
LL | let cont_iter = cont.iter();
| ^^^^^^^^^^^ lifetime `'r` required
|
help: add explicit lifetime `'r` to the type of `cont`
|
LL | fn check<'r, I: Iterator<Item=usize>, T: Itble<'r, usize, I>>(cont: &'r T) -> bool
| ++

error: aborting due to 1 previous error

Expand Down
8 changes: 6 additions & 2 deletions tests/ui/issues/issue-14285.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
error[E0621]: explicit lifetime required in the type of `a`
--> $DIR/issue-14285.rs:12:5
|
LL | fn foo<'a>(a: &dyn Foo) -> B<'a> {
| -------- help: add explicit lifetime `'a` to the type of `a`: `&'a (dyn Foo + 'a)`
LL | B(a)
| ^^^^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `a`
|
LL - fn foo<'a>(a: &dyn Foo) -> B<'a> {
LL + fn foo<'a>(a: &'a (dyn Foo + 'a)) -> B<'a> {
|

error: aborting due to 1 previous error

Expand Down
7 changes: 5 additions & 2 deletions tests/ui/issues/issue-15034.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
error[E0621]: explicit lifetime required in the type of `lexer`
--> $DIR/issue-15034.rs:17:9
|
LL | pub fn new(lexer: &'a mut Lexer) -> Parser<'a> {
| ------------- help: add explicit lifetime `'a` to the type of `lexer`: `&'a mut Lexer<'a>`
LL | Parser { lexer: lexer }
| ^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `lexer`
|
LL | pub fn new(lexer: &'a mut Lexer<'a>) -> Parser<'a> {
| ++++

error: aborting due to 1 previous error

Expand Down
7 changes: 5 additions & 2 deletions tests/ui/issues/issue-3154.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/issue-3154.rs:6:5
|
LL | fn thing<'a,Q>(x: &Q) -> Thing<'a,Q> {
| -- help: add explicit lifetime `'a` to the type of `x`: `&'a Q`
LL | Thing { x: x }
| ^^^^^^^^^^^^^^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `x`
|
LL | fn thing<'a,Q>(x: &'a Q) -> Thing<'a,Q> {
| ++

error: aborting due to 1 previous error

Expand Down
16 changes: 10 additions & 6 deletions tests/ui/issues/issue-40288-2.stderr
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/issue-40288-2.rs:9:5
|
LL | fn lifetime_transmute_slice<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T {
| -- help: add explicit lifetime `'a` to the type of `y`: `&'a T`
...
LL | out[0]
| ^^^^^^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `y`
|
LL | fn lifetime_transmute_slice<'a, T: ?Sized>(x: &'a T, y: &'a T) -> &'a T {
| ++

error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/issue-40288-2.rs:24:5
|
LL | fn lifetime_transmute_struct<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T {
| -- help: add explicit lifetime `'a` to the type of `y`: `&'a T`
...
LL | out.head
| ^^^^^^^^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `y`
|
LL | fn lifetime_transmute_struct<'a, T: ?Sized>(x: &'a T, y: &'a T) -> &'a T {
| ++

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/42701_one_named_and_one_anonymous.rs:10:9
|
LL | fn foo2<'a>(a: &'a Foo, x: &i32) -> &'a i32 {
| ---- help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
...
LL | &*x
| ^^^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `x`
|
LL | fn foo2<'a>(a: &'a Foo, x: &'a i32) -> &'a i32 {
| ++

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
error[E0621]: explicit lifetime required in the type of `other`
--> $DIR/ex1-return-one-existing-name-early-bound-in-struct.rs:11:21
|
LL | fn bar(&self, other: Foo) -> Foo<'a> {
| --- help: add explicit lifetime `'a` to the type of `other`: `Foo<'a>`
...
LL | other
| ^^^^^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `other`
|
LL | fn bar(&self, other: Foo<'a>) -> Foo<'a> {
| ++++

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/ex1-return-one-existing-name-if-else-2.rs:2:16
|
LL | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
| ---- help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
LL | if x > y { x } else { y }
| ^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `x`
|
LL | fn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 {
| ++

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
error[E0621]: explicit lifetime required in parameter type
--> $DIR/ex1-return-one-existing-name-if-else-3.rs:2:27
|
LL | fn foo<'a>((x, y): (&'a i32, &i32)) -> &'a i32 {
| --------------- help: add explicit lifetime `'a` to type: `(&'a i32, &'a i32)`
LL | if x > y { x } else { y }
| ^ lifetime `'a` required
|
help: add explicit lifetime `'a` to type
|
LL | fn foo<'a>((x, y): (&'a i32, &'a i32)) -> &'a i32 {
| ++

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-2.rs:4:15
|
LL | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
| ---- help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
LL | if x > y { x } else { y }
| ^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `x`
|
LL | fn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 {
| ++

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-3.rs:7:36
|
LL | fn foo<'a>(&'a self, x: &i32) -> &i32 {
| ---- help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
LL | if true { &self.field } else { x }
| ^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `x`
|
LL | fn foo<'a>(&'a self, x: &'a i32) -> &i32 {
| ++

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/ex1-return-one-existing-name-if-else.rs:2:27
|
LL | fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 {
| ---- help: add explicit lifetime `'a` to the type of `y`: `&'a i32`
LL | if x > y { x } else { y }
| ^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `y`
|
LL | fn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 {
| ++

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/ex2a-push-one-existing-name-2.rs:6:5
|
LL | fn foo<'a>(x: Ref<i32>, y: &mut Vec<Ref<'a, i32>>) {
| -------- help: add explicit lifetime `'a` to the type of `x`: `Ref<'a, i32>`
LL | y.push(x);
| ^^^^^^^^^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `x`
|
LL | fn foo<'a>(x: Ref<'a, i32>, y: &mut Vec<Ref<'a, i32>>) {
| +++

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/ex2a-push-one-existing-name-early-bound.rs:8:5
|
LL | fn baz<'a, 'b, T>(x: &mut Vec<&'a T>, y: &T)
| -- help: add explicit lifetime `'a` to the type of `y`: `&'a T`
...
LL | x.push(y);
| ^^^^^^^^^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `y`
|
LL | fn baz<'a, 'b, T>(x: &mut Vec<&'a T>, y: &'a T)
| ++

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/ex2a-push-one-existing-name.rs:6:5
|
LL | fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<i32>) {
| -------- help: add explicit lifetime `'a` to the type of `y`: `Ref<'a, i32>`
LL | x.push(y);
| ^^^^^^^^^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `y`
|
LL | fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<'a, i32>) {
| +++

error: aborting due to 1 previous error

Expand Down
9 changes: 6 additions & 3 deletions tests/ui/lifetimes/noisy-follow-up-erro.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ LL | struct Foo<'c, 'd>(&'c (), &'d ());
error[E0621]: explicit lifetime required in the type of `foo`
--> $DIR/noisy-follow-up-erro.rs:14:9
|
LL | fn boom(&self, foo: &mut Foo<'_, '_, 'a>) -> Result<(), &'a ()> {
| -------------------- help: add explicit lifetime `'a` to the type of `foo`: `&mut Foo<'_, 'a>`
LL |
LL | self.bar().map_err(|()| foo.acc(self))?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `foo`
|
LL - fn boom(&self, foo: &mut Foo<'_, '_, 'a>) -> Result<(), &'a ()> {
LL + fn boom(&self, foo: &mut Foo<'_, 'a>) -> Result<(), &'a ()> {
|

error: aborting due to 2 previous errors

Expand Down
Loading
Loading