Skip to content

Commit 78e36a0

Browse files
committed
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 { | ++ ```
1 parent df8102f commit 78e36a0

25 files changed

+143
-72
lines changed

compiler/rustc_trait_selection/src/errors.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,8 @@ pub enum ExplicitLifetimeRequired<'a> {
759759
#[suggestion(
760760
trait_selection_explicit_lifetime_required_sugg_with_ident,
761761
code = "{new_ty}",
762-
applicability = "unspecified"
762+
applicability = "unspecified",
763+
style = "verbose"
763764
)]
764765
new_ty_span: Span,
765766
#[skip_arg]
@@ -774,7 +775,8 @@ pub enum ExplicitLifetimeRequired<'a> {
774775
#[suggestion(
775776
trait_selection_explicit_lifetime_required_sugg_with_param_type,
776777
code = "{new_ty}",
777-
applicability = "unspecified"
778+
applicability = "unspecified",
779+
style = "verbose"
778780
)]
779781
new_ty_span: Span,
780782
#[skip_arg]
@@ -1462,7 +1464,8 @@ pub enum SuggestAccessingField<'a> {
14621464
#[suggestion(
14631465
trait_selection_suggest_accessing_field,
14641466
code = "{snippet}.{name}",
1465-
applicability = "maybe-incorrect"
1467+
applicability = "maybe-incorrect",
1468+
style = "verbose"
14661469
)]
14671470
Safe {
14681471
#[primary_span]
@@ -1474,7 +1477,8 @@ pub enum SuggestAccessingField<'a> {
14741477
#[suggestion(
14751478
trait_selection_suggest_accessing_field,
14761479
code = "unsafe {{ {snippet}.{name} }}",
1477-
applicability = "maybe-incorrect"
1480+
applicability = "maybe-incorrect",
1481+
style = "verbose"
14781482
)]
14791483
Unsafe {
14801484
#[primary_span]

tests/ui/async-await/async-closures/without-precise-captures-we-are-powerless.stderr

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ LL | }
106106
error[E0621]: explicit lifetime required in the type of `x`
107107
--> $DIR/without-precise-captures-we-are-powerless.rs:38:5
108108
|
109-
LL | fn through_field_and_ref<'a>(x: &S<'a>) {
110-
| ------ help: add explicit lifetime `'a` to the type of `x`: `&'a S<'a>`
111-
...
112109
LL | outlives::<'a>(call_once(c));
113110
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
111+
|
112+
help: add explicit lifetime `'a` to the type of `x`
113+
|
114+
LL | fn through_field_and_ref<'a>(x: &'a S<'a>) {
115+
| ++
114116

115117
error[E0597]: `c` does not live long enough
116118
--> $DIR/without-precise-captures-we-are-powerless.rs:43:20
@@ -131,11 +133,13 @@ LL | }
131133
error[E0621]: explicit lifetime required in the type of `x`
132134
--> $DIR/without-precise-captures-we-are-powerless.rs:44:5
133135
|
134-
LL | fn through_field_and_ref_move<'a>(x: &S<'a>) {
135-
| ------ help: add explicit lifetime `'a` to the type of `x`: `&'a S<'a>`
136-
...
137136
LL | outlives::<'a>(call_once(c));
138137
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
138+
|
139+
help: add explicit lifetime `'a` to the type of `x`
140+
|
141+
LL | fn through_field_and_ref_move<'a>(x: &'a S<'a>) {
142+
| ++
139143

140144
error: aborting due to 10 previous errors
141145

tests/ui/async-await/issues/issue-63388-1.stderr

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ LL | ) -> &dyn Foo
1212
error[E0621]: explicit lifetime required in the type of `foo`
1313
--> $DIR/issue-63388-1.rs:14:9
1414
|
15-
LL | &'a self, foo: &dyn Foo
16-
| -------- help: add explicit lifetime `'a` to the type of `foo`: `&'a (dyn Foo + 'a)`
17-
...
1815
LL | foo
1916
| ^^^ lifetime `'a` required
17+
|
18+
help: add explicit lifetime `'a` to the type of `foo`
19+
|
20+
LL - &'a self, foo: &dyn Foo
21+
LL + &'a self, foo: &'a (dyn Foo + 'a)
22+
|
2023

2124
error: aborting due to 1 previous error; 1 warning emitted
2225

tests/ui/impl-trait/must_outlive_least_region_or_bound.stderr

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ error[E0621]: explicit lifetime required in the type of `x`
6565
--> $DIR/must_outlive_least_region_or_bound.rs:15:41
6666
|
6767
LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x }
68-
| ---- ^ lifetime `'a` required
69-
| |
70-
| help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
68+
| ^ lifetime `'a` required
69+
|
70+
help: add explicit lifetime `'a` to the type of `x`
71+
|
72+
LL | fn foo<'a>(x: &'a i32) -> impl Copy + 'a { x }
73+
| ++
7174

7275
error: lifetime may not live long enough
7376
--> $DIR/must_outlive_least_region_or_bound.rs:30:55

tests/ui/issues/issue-13058.stderr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
error[E0621]: explicit lifetime required in the type of `cont`
22
--> $DIR/issue-13058.rs:14:21
33
|
4-
LL | fn check<'r, I: Iterator<Item=usize>, T: Itble<'r, usize, I>>(cont: &T) -> bool
5-
| -- help: add explicit lifetime `'r` to the type of `cont`: `&'r T`
6-
LL | {
74
LL | let cont_iter = cont.iter();
85
| ^^^^^^^^^^^ lifetime `'r` required
6+
|
7+
help: add explicit lifetime `'r` to the type of `cont`
8+
|
9+
LL | fn check<'r, I: Iterator<Item=usize>, T: Itble<'r, usize, I>>(cont: &'r T) -> bool
10+
| ++
911

1012
error: aborting due to 1 previous error
1113

tests/ui/issues/issue-14285.stderr

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
error[E0621]: explicit lifetime required in the type of `a`
22
--> $DIR/issue-14285.rs:12:5
33
|
4-
LL | fn foo<'a>(a: &dyn Foo) -> B<'a> {
5-
| -------- help: add explicit lifetime `'a` to the type of `a`: `&'a (dyn Foo + 'a)`
64
LL | B(a)
75
| ^^^^ lifetime `'a` required
6+
|
7+
help: add explicit lifetime `'a` to the type of `a`
8+
|
9+
LL - fn foo<'a>(a: &dyn Foo) -> B<'a> {
10+
LL + fn foo<'a>(a: &'a (dyn Foo + 'a)) -> B<'a> {
11+
|
812

913
error: aborting due to 1 previous error
1014

tests/ui/issues/issue-15034.stderr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0621]: explicit lifetime required in the type of `lexer`
22
--> $DIR/issue-15034.rs:17:9
33
|
4-
LL | pub fn new(lexer: &'a mut Lexer) -> Parser<'a> {
5-
| ------------- help: add explicit lifetime `'a` to the type of `lexer`: `&'a mut Lexer<'a>`
64
LL | Parser { lexer: lexer }
75
| ^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
6+
|
7+
help: add explicit lifetime `'a` to the type of `lexer`
8+
|
9+
LL | pub fn new(lexer: &'a mut Lexer<'a>) -> Parser<'a> {
10+
| ++++
811

912
error: aborting due to 1 previous error
1013

tests/ui/issues/issue-3154.stderr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0621]: explicit lifetime required in the type of `x`
22
--> $DIR/issue-3154.rs:6:5
33
|
4-
LL | fn thing<'a,Q>(x: &Q) -> Thing<'a,Q> {
5-
| -- help: add explicit lifetime `'a` to the type of `x`: `&'a Q`
64
LL | Thing { x: x }
75
| ^^^^^^^^^^^^^^ lifetime `'a` required
6+
|
7+
help: add explicit lifetime `'a` to the type of `x`
8+
|
9+
LL | fn thing<'a,Q>(x: &'a Q) -> Thing<'a,Q> {
10+
| ++
811

912
error: aborting due to 1 previous error
1013

tests/ui/issues/issue-40288-2.stderr

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
error[E0621]: explicit lifetime required in the type of `y`
22
--> $DIR/issue-40288-2.rs:9:5
33
|
4-
LL | fn lifetime_transmute_slice<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T {
5-
| -- help: add explicit lifetime `'a` to the type of `y`: `&'a T`
6-
...
74
LL | out[0]
85
| ^^^^^^ lifetime `'a` required
6+
|
7+
help: add explicit lifetime `'a` to the type of `y`
8+
|
9+
LL | fn lifetime_transmute_slice<'a, T: ?Sized>(x: &'a T, y: &'a T) -> &'a T {
10+
| ++
911

1012
error[E0621]: explicit lifetime required in the type of `y`
1113
--> $DIR/issue-40288-2.rs:24:5
1214
|
13-
LL | fn lifetime_transmute_struct<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T {
14-
| -- help: add explicit lifetime `'a` to the type of `y`: `&'a T`
15-
...
1615
LL | out.head
1716
| ^^^^^^^^ lifetime `'a` required
17+
|
18+
help: add explicit lifetime `'a` to the type of `y`
19+
|
20+
LL | fn lifetime_transmute_struct<'a, T: ?Sized>(x: &'a T, y: &'a T) -> &'a T {
21+
| ++
1822

1923
error: aborting due to 2 previous errors
2024

tests/ui/lifetimes/lifetime-errors/42701_one_named_and_one_anonymous.stderr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
error[E0621]: explicit lifetime required in the type of `x`
22
--> $DIR/42701_one_named_and_one_anonymous.rs:10:9
33
|
4-
LL | fn foo2<'a>(a: &'a Foo, x: &i32) -> &'a i32 {
5-
| ---- help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
6-
...
74
LL | &*x
85
| ^^^ lifetime `'a` required
6+
|
7+
help: add explicit lifetime `'a` to the type of `x`
8+
|
9+
LL | fn foo2<'a>(a: &'a Foo, x: &'a i32) -> &'a i32 {
10+
| ++
911

1012
error: aborting due to 1 previous error
1113

tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-early-bound-in-struct.stderr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
error[E0621]: explicit lifetime required in the type of `other`
22
--> $DIR/ex1-return-one-existing-name-early-bound-in-struct.rs:11:21
33
|
4-
LL | fn bar(&self, other: Foo) -> Foo<'a> {
5-
| --- help: add explicit lifetime `'a` to the type of `other`: `Foo<'a>`
6-
...
74
LL | other
85
| ^^^^^ lifetime `'a` required
6+
|
7+
help: add explicit lifetime `'a` to the type of `other`
8+
|
9+
LL | fn bar(&self, other: Foo<'a>) -> Foo<'a> {
10+
| ++++
911

1012
error: aborting due to 1 previous error
1113

tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-if-else-2.stderr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0621]: explicit lifetime required in the type of `x`
22
--> $DIR/ex1-return-one-existing-name-if-else-2.rs:2:16
33
|
4-
LL | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
5-
| ---- help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
64
LL | if x > y { x } else { y }
75
| ^ lifetime `'a` required
6+
|
7+
help: add explicit lifetime `'a` to the type of `x`
8+
|
9+
LL | fn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 {
10+
| ++
811

912
error: aborting due to 1 previous error
1013

tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-if-else-3.stderr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0621]: explicit lifetime required in parameter type
22
--> $DIR/ex1-return-one-existing-name-if-else-3.rs:2:27
33
|
4-
LL | fn foo<'a>((x, y): (&'a i32, &i32)) -> &'a i32 {
5-
| --------------- help: add explicit lifetime `'a` to type: `(&'a i32, &'a i32)`
64
LL | if x > y { x } else { y }
75
| ^ lifetime `'a` required
6+
|
7+
help: add explicit lifetime `'a` to type
8+
|
9+
LL | fn foo<'a>((x, y): (&'a i32, &'a i32)) -> &'a i32 {
10+
| ++
811

912
error: aborting due to 1 previous error
1013

tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-if-else-using-impl-2.stderr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0621]: explicit lifetime required in the type of `x`
22
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-2.rs:4:15
33
|
4-
LL | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
5-
| ---- help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
64
LL | if x > y { x } else { y }
75
| ^ lifetime `'a` required
6+
|
7+
help: add explicit lifetime `'a` to the type of `x`
8+
|
9+
LL | fn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 {
10+
| ++
811

912
error: aborting due to 1 previous error
1013

tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-if-else-using-impl-3.stderr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ LL | fn foo<'a>(&'a self, x: &i32) -> &i32 {
1111
error[E0621]: explicit lifetime required in the type of `x`
1212
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-3.rs:9:36
1313
|
14-
LL | fn foo<'a>(&'a self, x: &i32) -> &i32 {
15-
| ---- help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
16-
...
1714
LL | if true { &self.field } else { x }
1815
| ^ lifetime `'a` required
16+
|
17+
help: add explicit lifetime `'a` to the type of `x`
18+
|
19+
LL | fn foo<'a>(&'a self, x: &'a i32) -> &i32 {
20+
| ++
1921

2022
error: aborting due to 1 previous error; 1 warning emitted
2123

tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-if-else.stderr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0621]: explicit lifetime required in the type of `y`
22
--> $DIR/ex1-return-one-existing-name-if-else.rs:2:27
33
|
4-
LL | fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 {
5-
| ---- help: add explicit lifetime `'a` to the type of `y`: `&'a i32`
64
LL | if x > y { x } else { y }
75
| ^ lifetime `'a` required
6+
|
7+
help: add explicit lifetime `'a` to the type of `y`
8+
|
9+
LL | fn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 {
10+
| ++
811

912
error: aborting due to 1 previous error
1013

tests/ui/lifetimes/lifetime-errors/ex2a-push-one-existing-name-2.stderr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0621]: explicit lifetime required in the type of `x`
22
--> $DIR/ex2a-push-one-existing-name-2.rs:6:5
33
|
4-
LL | fn foo<'a>(x: Ref<i32>, y: &mut Vec<Ref<'a, i32>>) {
5-
| -------- help: add explicit lifetime `'a` to the type of `x`: `Ref<'a, i32>`
64
LL | y.push(x);
75
| ^^^^^^^^^ lifetime `'a` required
6+
|
7+
help: add explicit lifetime `'a` to the type of `x`
8+
|
9+
LL | fn foo<'a>(x: Ref<'a, i32>, y: &mut Vec<Ref<'a, i32>>) {
10+
| +++
811

912
error: aborting due to 1 previous error
1013

tests/ui/lifetimes/lifetime-errors/ex2a-push-one-existing-name-early-bound.stderr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
error[E0621]: explicit lifetime required in the type of `y`
22
--> $DIR/ex2a-push-one-existing-name-early-bound.rs:8:5
33
|
4-
LL | fn baz<'a, 'b, T>(x: &mut Vec<&'a T>, y: &T)
5-
| -- help: add explicit lifetime `'a` to the type of `y`: `&'a T`
6-
...
74
LL | x.push(y);
85
| ^^^^^^^^^ lifetime `'a` required
6+
|
7+
help: add explicit lifetime `'a` to the type of `y`
8+
|
9+
LL | fn baz<'a, 'b, T>(x: &mut Vec<&'a T>, y: &'a T)
10+
| ++
911

1012
error: aborting due to 1 previous error
1113

tests/ui/lifetimes/lifetime-errors/ex2a-push-one-existing-name.stderr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0621]: explicit lifetime required in the type of `y`
22
--> $DIR/ex2a-push-one-existing-name.rs:6:5
33
|
4-
LL | fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<i32>) {
5-
| -------- help: add explicit lifetime `'a` to the type of `y`: `Ref<'a, i32>`
64
LL | x.push(y);
75
| ^^^^^^^^^ lifetime `'a` required
6+
|
7+
help: add explicit lifetime `'a` to the type of `y`
8+
|
9+
LL | fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<'a, i32>) {
10+
| +++
811

912
error: aborting due to 1 previous error
1013

tests/ui/lifetimes/noisy-follow-up-erro.stderr

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ LL | struct Foo<'c, 'd>(&'c (), &'d ());
1515
error[E0621]: explicit lifetime required in the type of `foo`
1616
--> $DIR/noisy-follow-up-erro.rs:14:9
1717
|
18-
LL | fn boom(&self, foo: &mut Foo<'_, '_, 'a>) -> Result<(), &'a ()> {
19-
| -------------------- help: add explicit lifetime `'a` to the type of `foo`: `&mut Foo<'_, 'a>`
20-
LL |
2118
LL | self.bar().map_err(|()| foo.acc(self))?;
2219
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
20+
|
21+
help: add explicit lifetime `'a` to the type of `foo`
22+
|
23+
LL - fn boom(&self, foo: &mut Foo<'_, '_, 'a>) -> Result<(), &'a ()> {
24+
LL + fn boom(&self, foo: &mut Foo<'_, 'a>) -> Result<(), &'a ()> {
25+
|
2326

2427
error: aborting due to 2 previous errors
2528

0 commit comments

Comments
 (0)