Skip to content

Commit e3c1f72

Browse files
committed
Make "add lifetime" suggestion verbose
1 parent d7cfefa commit e3c1f72

28 files changed

+257
-128
lines changed

Diff for: compiler/rustc_resolve/src/late/diagnostics.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -2812,15 +2812,10 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
28122812
&mut err,
28132813
Some(lifetime_ref.ident.name.as_str()),
28142814
|err, _, span, message, suggestion, span_suggs| {
2815-
err.multipart_suggestion_with_style(
2815+
err.multipart_suggestion_verbose(
28162816
message,
28172817
std::iter::once((span, suggestion)).chain(span_suggs.clone()).collect(),
28182818
Applicability::MaybeIncorrect,
2819-
if span_suggs.is_empty() {
2820-
SuggestionStyle::ShowCode
2821-
} else {
2822-
SuggestionStyle::ShowAlways
2823-
},
28242819
);
28252820
true
28262821
},

Diff for: tests/ui/associated-inherent-types/issue-109299.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ error[E0261]: use of undeclared lifetime name `'d`
22
--> $DIR/issue-109299.rs:6:12
33
|
44
LL | impl Lexer<'d> {
5-
| - ^^ undeclared lifetime
6-
| |
7-
| help: consider introducing lifetime `'d` here: `<'d>`
5+
| ^^ undeclared lifetime
6+
|
7+
help: consider introducing lifetime `'d` here
8+
|
9+
LL | impl<'d> Lexer<'d> {
10+
| ++++
811

912
error: aborting due to 1 previous error
1013

Diff for: tests/ui/borrowck/generic_const_early_param.stderr

+11-6
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,24 @@ LL | struct DataWrapper<'static> {
77
error[E0261]: use of undeclared lifetime name `'a`
88
--> $DIR/generic_const_early_param.rs:6:12
99
|
10-
LL | struct DataWrapper<'static> {
11-
| - help: consider introducing lifetime `'a` here: `'a,`
12-
LL |
1310
LL | data: &'a [u8; Self::SIZE],
1411
| ^^ undeclared lifetime
12+
|
13+
help: consider introducing lifetime `'a` here
14+
|
15+
LL | struct DataWrapper<'a, 'static> {
16+
| +++
1517

1618
error[E0261]: use of undeclared lifetime name `'a`
1719
--> $DIR/generic_const_early_param.rs:10:18
1820
|
1921
LL | impl DataWrapper<'a> {
20-
| - ^^ undeclared lifetime
21-
| |
22-
| help: consider introducing lifetime `'a` here: `<'a>`
22+
| ^^ undeclared lifetime
23+
|
24+
help: consider introducing lifetime `'a` here
25+
|
26+
LL | impl<'a> DataWrapper<'a> {
27+
| ++++
2328

2429
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
2530
--> $DIR/generic_const_early_param.rs:1:12

Diff for: tests/ui/cast/ice-cast-type-with-error-124848.stderr

+16-9
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,34 @@ error[E0261]: use of undeclared lifetime name `'unpinned`
22
--> $DIR/ice-cast-type-with-error-124848.rs:7:32
33
|
44
LL | struct MyType<'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
5-
| - ^^^^^^^^^ undeclared lifetime
6-
| |
7-
| help: consider introducing lifetime `'unpinned` here: `'unpinned,`
5+
| ^^^^^^^^^ undeclared lifetime
6+
|
7+
help: consider introducing lifetime `'unpinned` here
8+
|
9+
LL | struct MyType<'unpinned, 'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
10+
| ++++++++++
811

912
error[E0261]: use of undeclared lifetime name `'a`
1013
--> $DIR/ice-cast-type-with-error-124848.rs:14:53
1114
|
12-
LL | fn main() {
13-
| - help: consider introducing lifetime `'a` here: `<'a>`
14-
...
1515
LL | let bad_addr = &unpinned as *const Cell<Option<&'a mut MyType<'a>>> as usize;
1616
| ^^ undeclared lifetime
17+
|
18+
help: consider introducing lifetime `'a` here
19+
|
20+
LL | fn main<'a>() {
21+
| ++++
1722

1823
error[E0261]: use of undeclared lifetime name `'a`
1924
--> $DIR/ice-cast-type-with-error-124848.rs:14:67
2025
|
21-
LL | fn main() {
22-
| - help: consider introducing lifetime `'a` here: `<'a>`
23-
...
2426
LL | let bad_addr = &unpinned as *const Cell<Option<&'a mut MyType<'a>>> as usize;
2527
| ^^ undeclared lifetime
28+
|
29+
help: consider introducing lifetime `'a` here
30+
|
31+
LL | fn main<'a>() {
32+
| ++++
2633

2734
error[E0412]: cannot find type `Pin` in this scope
2835
--> $DIR/ice-cast-type-with-error-124848.rs:7:60

Diff for: tests/ui/const-generics/generic_const_exprs/unresolved_lifetimes_error.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0261]: use of undeclared lifetime name `'a`
22
--> $DIR/unresolved_lifetimes_error.rs:5:13
33
|
4-
LL | fn foo() -> [(); {
5-
| - help: consider introducing lifetime `'a` here: `<'a>`
64
LL | let a: &'a ();
75
| ^^ undeclared lifetime
6+
|
7+
help: consider introducing lifetime `'a` here
8+
|
9+
LL | fn foo<'a>() -> [(); {
10+
| ++++
811

912
error: aborting due to 1 previous error
1013

Diff for: tests/ui/const-generics/ice-unexpected-inference-var-122549.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ error[E0261]: use of undeclared lifetime name `'a`
1717
--> $DIR/ice-unexpected-inference-var-122549.rs:11:34
1818
|
1919
LL | struct ConstChunksExact<'rem, T: 'a, const N: usize> {}
20-
| - ^^ undeclared lifetime
21-
| |
22-
| help: consider introducing lifetime `'a` here: `'a,`
20+
| ^^ undeclared lifetime
21+
|
22+
help: consider introducing lifetime `'a` here
23+
|
24+
LL | struct ConstChunksExact<'a, 'rem, T: 'a, const N: usize> {}
25+
| +++
2326

2427
error[E0046]: not all trait items implemented, missing: `const_chunks_exact`
2528
--> $DIR/ice-unexpected-inference-var-122549.rs:9:1

Diff for: tests/ui/const_prop/ice-type-mismatch-when-copying-112824.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ error[E0261]: use of undeclared lifetime name `'a`
22
--> $DIR/ice-type-mismatch-when-copying-112824.rs:5:21
33
|
44
LL | pub struct Opcode2(&'a S);
5-
| - ^^ undeclared lifetime
6-
| |
7-
| help: consider introducing lifetime `'a` here: `<'a>`
5+
| ^^ undeclared lifetime
6+
|
7+
help: consider introducing lifetime `'a` here
8+
|
9+
LL | pub struct Opcode2<'a>(&'a S);
10+
| ++++
811

912
error[E0412]: cannot find type `S` in this scope
1013
--> $DIR/ice-type-mismatch-when-copying-112824.rs:5:24

Diff for: tests/ui/dyn-compatibility/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.stderr

+12-6
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,12 @@ error[E0261]: use of undeclared lifetime name `'a`
139139
--> $DIR/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.rs:96:12
140140
|
141141
LL | fn bar(_: &'a Trait) {}
142-
| - ^^ undeclared lifetime
143-
| |
144-
| help: consider introducing lifetime `'a` here: `<'a>`
142+
| ^^ undeclared lifetime
143+
|
144+
help: consider introducing lifetime `'a` here
145+
|
146+
LL | fn bar<'a>(_: &'a Trait) {}
147+
| ++++
145148

146149
error[E0106]: missing lifetime specifier
147150
--> $DIR/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.rs:110:13
@@ -171,9 +174,12 @@ error[E0261]: use of undeclared lifetime name `'a`
171174
--> $DIR/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.rs:122:17
172175
|
173176
LL | fn kitten() -> &'a Trait {
174-
| - ^^ undeclared lifetime
175-
| |
176-
| help: consider introducing lifetime `'a` here: `<'a>`
177+
| ^^ undeclared lifetime
178+
|
179+
help: consider introducing lifetime `'a` here
180+
|
181+
LL | fn kitten<'a>() -> &'a Trait {
182+
| ++++
177183

178184
error[E0106]: missing lifetime specifier
179185
--> $DIR/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.rs:133:16

Diff for: tests/ui/error-codes/E0261.stderr

+11-5
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@ error[E0261]: use of undeclared lifetime name `'a`
22
--> $DIR/E0261.rs:1:12
33
|
44
LL | fn foo(x: &'a str) { }
5-
| - ^^ undeclared lifetime
6-
| |
7-
| help: consider introducing lifetime `'a` here: `<'a>`
5+
| ^^ undeclared lifetime
6+
|
7+
help: consider introducing lifetime `'a` here
8+
|
9+
LL | fn foo<'a>(x: &'a str) { }
10+
| ++++
811

912
error[E0261]: use of undeclared lifetime name `'a`
1013
--> $DIR/E0261.rs:5:9
1114
|
12-
LL | struct Foo {
13-
| - help: consider introducing lifetime `'a` here: `<'a>`
1415
LL | x: &'a str,
1516
| ^^ undeclared lifetime
17+
|
18+
help: consider introducing lifetime `'a` here
19+
|
20+
LL | struct Foo<'a> {
21+
| ++++
1622

1723
error: aborting due to 2 previous errors
1824

Diff for: tests/ui/generics/generic-extern-lifetime.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ error[E0261]: use of undeclared lifetime name `'a`
22
--> $DIR/generic-extern-lifetime.rs:6:26
33
|
44
LL | pub fn life2<'b>(x: &'a i32, y: &'b i32);
5-
| - ^^ undeclared lifetime
6-
| |
7-
| help: consider introducing lifetime `'a` here: `'a,`
5+
| ^^ undeclared lifetime
6+
|
7+
help: consider introducing lifetime `'a` here
8+
|
9+
LL | pub fn life2<'a, 'b>(x: &'a i32, y: &'b i32);
10+
| +++
811

912
error[E0261]: use of undeclared lifetime name `'a`
1013
--> $DIR/generic-extern-lifetime.rs:8:37

Diff for: tests/ui/generics/impl-block-params-declared-in-wrong-spot-issue-113073.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ error[E0261]: use of undeclared lifetime name `'a`
22
--> $DIR/impl-block-params-declared-in-wrong-spot-issue-113073.rs:7:13
33
|
44
LL | impl Foo<T: 'a + Default> for u8 {}
5-
| - ^^ undeclared lifetime
6-
| |
7-
| help: consider introducing lifetime `'a` here: `<'a>`
5+
| ^^ undeclared lifetime
6+
|
7+
help: consider introducing lifetime `'a` here
8+
|
9+
LL | impl<'a> Foo<T: 'a + Default> for u8 {}
10+
| ++++
811

912
error[E0229]: associated item constraints are not allowed here
1013
--> $DIR/impl-block-params-declared-in-wrong-spot-issue-113073.rs:3:10

Diff for: tests/ui/impl-trait/precise-capturing/bad-lifetimes.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ error[E0261]: use of undeclared lifetime name `'missing`
1414
--> $DIR/bad-lifetimes.rs:8:37
1515
|
1616
LL | fn missing_lt() -> impl Sized + use<'missing> {}
17-
| - ^^^^^^^^ undeclared lifetime
18-
| |
19-
| help: consider introducing lifetime `'missing` here: `<'missing>`
17+
| ^^^^^^^^ undeclared lifetime
18+
|
19+
help: consider introducing lifetime `'missing` here
20+
|
21+
LL | fn missing_lt<'missing>() -> impl Sized + use<'missing> {}
22+
| ++++++++++
2023

2124
error: expected lifetime parameter in `use<...>` precise captures list, found `'_`
2225
--> $DIR/bad-lifetimes.rs:1:39

Diff for: tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ error[E0261]: use of undeclared lifetime name `'q`
2323
--> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:14:21
2424
|
2525
LL | impl<'static> Query<'q> {
26-
| - ^^ undeclared lifetime
27-
| |
28-
| help: consider introducing lifetime `'q` here: `'q,`
26+
| ^^ undeclared lifetime
27+
|
28+
help: consider introducing lifetime `'q` here
29+
|
30+
LL | impl<'q, 'static> Query<'q> {
31+
| +++
2932

3033
error[E0392]: lifetime parameter `'q` is never used
3134
--> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:11:14

Diff for: tests/ui/inference/issue-107090.stderr

+18-7
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,23 @@ error[E0261]: use of undeclared lifetime name `'b`
3333
--> $DIR/issue-107090.rs:11:47
3434
|
3535
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
36-
| - ^^ undeclared lifetime
37-
| |
38-
| help: consider introducing lifetime `'b` here: `'b,`
36+
| ^^ undeclared lifetime
37+
|
38+
help: consider introducing lifetime `'b` here
39+
|
40+
LL | impl<'b, 'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
41+
| +++
3942

4043
error[E0261]: use of undeclared lifetime name `'out`
4144
--> $DIR/issue-107090.rs:11:67
4245
|
4346
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
44-
| - help: consider introducing lifetime `'out` here: `'out,` ^^^^ undeclared lifetime
47+
| ^^^^ undeclared lifetime
48+
|
49+
help: consider introducing lifetime `'out` here
50+
|
51+
LL | impl<'out, 'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
52+
| +++++
4553

4654
error[E0261]: use of undeclared lifetime name `'out`
4755
--> $DIR/issue-107090.rs:14:49
@@ -62,9 +70,12 @@ error[E0261]: use of undeclared lifetime name `'short`
6270
--> $DIR/issue-107090.rs:20:68
6371
|
6472
LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T {
65-
| - ^^^^^^ undeclared lifetime
66-
| |
67-
| help: consider introducing lifetime `'short` here: `'short,`
73+
| ^^^^^^ undeclared lifetime
74+
|
75+
help: consider introducing lifetime `'short` here
76+
|
77+
LL | fn badboi<'short, 'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T {
78+
| +++++++
6879

6980
error: aborting due to 6 previous errors
7081

Diff for: tests/ui/lifetimes/issue-107988.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ error[E0261]: use of undeclared lifetime name `'tcx`
22
--> $DIR/issue-107988.rs:7:52
33
|
44
LL | impl<T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
5-
| - ^^^^ undeclared lifetime
6-
| |
7-
| help: consider introducing lifetime `'tcx` here: `'tcx,`
5+
| ^^^^ undeclared lifetime
6+
|
7+
help: consider introducing lifetime `'tcx` here
8+
|
9+
LL | impl<'tcx, T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
10+
| +++++
811

912
error[E0261]: use of undeclared lifetime name `'tcx`
1013
--> $DIR/issue-107988.rs:7:30

Diff for: tests/ui/lifetimes/missing-lifetime-in-assoc-type-2.stderr

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ LL ~ type Item = &'a T;
1515
error[E0261]: use of undeclared lifetime name `'a`
1616
--> $DIR/missing-lifetime-in-assoc-type-2.rs:7:57
1717
|
18-
LL | impl IntoIterator for &S {
19-
| - help: consider introducing lifetime `'a` here: `<'a>`
20-
...
2118
LL | type IntoIter = std::collections::btree_map::Values<'a, i32, T>;
2219
| ^^ undeclared lifetime
20+
|
21+
help: consider introducing lifetime `'a` here
22+
|
23+
LL | impl<'a> IntoIterator for &S {
24+
| ++++
2325

2426
error: aborting due to 2 previous errors
2527

Diff for: tests/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
error[E0261]: use of undeclared lifetime name `'b`
22
--> $DIR/undeclared-lifetime-used-in-debug-macro-issue-70152.rs:3:9
33
|
4-
LL | struct Test {
5-
| - help: consider introducing lifetime `'b` here: `<'b>`
64
LL | a: &'b str,
75
| ^^ undeclared lifetime
6+
|
7+
help: consider introducing lifetime `'b` here
8+
|
9+
LL | struct Test<'b> {
10+
| ++++
811

912
error[E0261]: use of undeclared lifetime name `'b`
1013
--> $DIR/undeclared-lifetime-used-in-debug-macro-issue-70152.rs:3:9
1114
|
1215
LL | #[derive(Eq, PartialEq)]
1316
| -- lifetime `'b` is missing in item created through this procedural macro
1417
LL | struct Test {
15-
| - help: consider introducing lifetime `'b` here: `<'b>`
1618
LL | a: &'b str,
1719
| ^^ undeclared lifetime
20+
|
21+
help: consider introducing lifetime `'b` here
22+
|
23+
LL | struct Test<'b> {
24+
| ++++
1825

1926
error[E0261]: use of undeclared lifetime name `'b`
2027
--> $DIR/undeclared-lifetime-used-in-debug-macro-issue-70152.rs:13:13

0 commit comments

Comments
 (0)