Make E0621 missing lifetime suggestion verbose

```
error[E0621]: explicit lifetime required in the type of `x`
  --> $DIR/42701_one_named_and_one_anonymous.rs:10:9
   |
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 {
   |                             ++
```
This commit is contained in:
Esteban Küber
2025-06-04 21:10:27 +00:00
parent 00b526212b
commit 3fce086d79
25 changed files with 143 additions and 71 deletions
+8 -4
View File
@@ -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]
@@ -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]
@@ -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]
@@ -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]
@@ -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
@@ -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
@@ -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
@@ -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
+5 -3
View File
@@ -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
+6 -2
View File
@@ -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
+5 -2
View File
@@ -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
+5 -2
View File
@@ -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
+10 -6
View File
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -21,11 +21,13 @@ LL | ss.r
error[E0621]: explicit lifetime required in the type of `ss`
--> $DIR/object-lifetime-default-from-box-error.rs:33:5
|
LL | fn store1<'b>(ss: &mut SomeStruct, b: Box<dyn SomeTrait+'b>) {
| --------------- help: add explicit lifetime `'b` to the type of `ss`: `&mut SomeStruct<'b>`
...
LL | ss.r = b;
| ^^^^ lifetime `'b` required
|
help: add explicit lifetime `'b` to the type of `ss`
|
LL | fn store1<'b>(ss: &mut SomeStruct<'b>, b: Box<dyn SomeTrait+'b>) {
| ++++
error: aborting due to 3 previous errors
@@ -1,8 +1,6 @@
error[E0621]: explicit lifetime required in the type of `s`
--> $DIR/regions-glb-free-free.rs:15:13
|
LL | pub fn set_desc(self, s: &str) -> Flag<'a> {
| ---- help: add explicit lifetime `'a` to the type of `s`: `&'a str`
LL | / Flag {
LL | | name: self.name,
LL | | desc: s,
@@ -10,6 +8,11 @@ LL | | max_count: self.max_count,
LL | | value: self.value
LL | | }
| |_____________^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `s`
|
LL | pub fn set_desc(self, s: &'a str) -> Flag<'a> {
| ++
error: aborting due to 1 previous error
@@ -2,9 +2,12 @@ error[E0621]: explicit lifetime required in the type of `p`
--> $DIR/regions-infer-at-fn-not-param.rs:13:57
|
LL | fn take1<'a>(p: Parameterized1) -> Parameterized1<'a> { p }
| -------------- ^ lifetime `'a` required
| |
| help: add explicit lifetime `'a` to the type of `p`: `Parameterized1<'a>`
| ^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `p`
|
LL | fn take1<'a>(p: Parameterized1<'a>) -> Parameterized1<'a> { p }
| ++++
error: aborting due to 1 previous error
@@ -101,15 +101,17 @@ LL + fn bat<'b, 'a, G: 'a + 'b, T>(g: G, dest: &'b mut T) -> impl FnOnce() + 'b
error[E0621]: explicit lifetime required in the type of `dest`
--> $DIR/missing-lifetimes-in-signature.rs:73:5
|
LL | fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a
| ------ help: add explicit lifetime `'a` to the type of `dest`: `&'a mut T`
...
LL | / move || {
LL | |
LL | |
LL | | *dest = g.get();
LL | | }
| |_____^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `dest`
|
LL | fn bat<'a, G: 'a, T>(g: G, dest: &'a mut T) -> impl FnOnce() + '_ + 'a
| ++
error[E0309]: the parameter type `G` may not live long enough
--> $DIR/missing-lifetimes-in-signature.rs:85:5
@@ -1,11 +1,13 @@
error[E0621]: explicit lifetime required in the type of `get`
--> $DIR/variance-trait-matching.rs:24:5
|
LL | fn get<'a, G>(get: &G) -> i32
| -- help: add explicit lifetime `'a` to the type of `get`: `&'a G`
...
LL | pick(get, &22)
| ^^^^^^^^^^^^^^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `get`
|
LL | fn get<'a, G>(get: &'a G) -> i32
| ++
error: aborting due to 1 previous error