Skip to content

Commit 2f8b715

Browse files
authored
Rollup merge of rust-lang#142981 - compiler-errors:verbose-missing-suggestion, r=estebank
Make missing lifetime suggestion verbose I keep seeing this suggestion when working on rustc, and it's annoying that it's inline. Part of rust-lang#141973. Feel free to close this if there's another PR already doing this. r? ``@estebank``
2 parents 2fc94f1 + 250b5d2 commit 2f8b715

27 files changed

+247
-123
lines changed

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,15 +3122,10 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
31223122
&mut err,
31233123
Some(lifetime_ref.ident.name.as_str()),
31243124
|err, _, span, message, suggestion, span_suggs| {
3125-
err.multipart_suggestion_with_style(
3125+
err.multipart_suggestion_verbose(
31263126
message,
31273127
std::iter::once((span, suggestion)).chain(span_suggs.clone()).collect(),
31283128
Applicability::MaybeIncorrect,
3129-
if span_suggs.is_empty() {
3130-
SuggestionStyle::ShowCode
3131-
} else {
3132-
SuggestionStyle::ShowAlways
3133-
},
31343129
);
31353130
true
31363131
},

tests/ui/associated-inherent-types/issue-109299.stderr

Lines changed: 6 additions & 3 deletions
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

tests/ui/borrowck/generic_const_early_param.stderr

Lines changed: 11 additions & 6 deletions
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

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

Lines changed: 16 additions & 9 deletions
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

tests/ui/const-generics/generic_const_exprs/unresolved_lifetimes_error.stderr

Lines changed: 5 additions & 2 deletions
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

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

Lines changed: 6 additions & 3 deletions
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

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

Lines changed: 6 additions & 3 deletions
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

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

Lines changed: 12 additions & 6 deletions
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

tests/ui/error-codes/E0261.stderr

Lines changed: 11 additions & 5 deletions
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

tests/ui/generics/generic-extern-lifetime.stderr

Lines changed: 6 additions & 3 deletions
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

0 commit comments

Comments
 (0)