Skip to content

Make missing lifetime suggestion verbose #142981

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 1 addition & 6 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3122,15 +3122,10 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
&mut err,
Some(lifetime_ref.ident.name.as_str()),
|err, _, span, message, suggestion, span_suggs| {
err.multipart_suggestion_with_style(
err.multipart_suggestion_verbose(
message,
std::iter::once((span, suggestion)).chain(span_suggs.clone()).collect(),
Applicability::MaybeIncorrect,
if span_suggs.is_empty() {
SuggestionStyle::ShowCode
} else {
SuggestionStyle::ShowAlways
},
);
true
},
Expand Down
9 changes: 6 additions & 3 deletions tests/ui/associated-inherent-types/issue-109299.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ error[E0261]: use of undeclared lifetime name `'d`
--> $DIR/issue-109299.rs:6:12
|
LL | impl Lexer<'d> {
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'d` here: `<'d>`
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'d` here
|
LL | impl<'d> Lexer<'d> {
| ++++

error: aborting due to 1 previous error

Expand Down
17 changes: 11 additions & 6 deletions tests/ui/borrowck/generic_const_early_param.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@ LL | struct DataWrapper<'static> {
error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/generic_const_early_param.rs:6:12
|
LL | struct DataWrapper<'static> {
| - help: consider introducing lifetime `'a` here: `'a,`
LL |
LL | data: &'a [u8; Self::SIZE],
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | struct DataWrapper<'a, 'static> {
| +++

error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/generic_const_early_param.rs:10:18
|
LL | impl DataWrapper<'a> {
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'a` here: `<'a>`
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | impl<'a> DataWrapper<'a> {
| ++++

warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/generic_const_early_param.rs:1:12
Expand Down
25 changes: 16 additions & 9 deletions tests/ui/cast/ice-cast-type-with-error-124848.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,34 @@ error[E0261]: use of undeclared lifetime name `'unpinned`
--> $DIR/ice-cast-type-with-error-124848.rs:7:32
|
LL | struct MyType<'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
| - ^^^^^^^^^ undeclared lifetime
| |
| help: consider introducing lifetime `'unpinned` here: `'unpinned,`
| ^^^^^^^^^ undeclared lifetime
|
help: consider introducing lifetime `'unpinned` here
|
LL | struct MyType<'unpinned, 'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
| ++++++++++

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

error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/ice-cast-type-with-error-124848.rs:14:67
|
LL | fn main() {
| - help: consider introducing lifetime `'a` here: `<'a>`
...
LL | let bad_addr = &unpinned as *const Cell<Option<&'a mut MyType<'a>>> as usize;
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | fn main<'a>() {
| ++++

error[E0412]: cannot find type `Pin` in this scope
--> $DIR/ice-cast-type-with-error-124848.rs:7:60
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/unresolved_lifetimes_error.rs:5:13
|
LL | fn foo() -> [(); {
| - help: consider introducing lifetime `'a` here: `<'a>`
LL | let a: &'a ();
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | fn foo<'a>() -> [(); {
| ++++

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/ice-unexpected-inference-var-122549.rs:11:34
|
LL | struct ConstChunksExact<'rem, T: 'a, const N: usize> {}
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'a` here: `'a,`
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | struct ConstChunksExact<'a, 'rem, T: 'a, const N: usize> {}
| +++

error[E0046]: not all trait items implemented, missing: `const_chunks_exact`
--> $DIR/ice-unexpected-inference-var-122549.rs:9:1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/ice-type-mismatch-when-copying-112824.rs:5:21
|
LL | pub struct Opcode2(&'a S);
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'a` here: `<'a>`
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | pub struct Opcode2<'a>(&'a S);
| ++++

error[E0412]: cannot find type `S` in this scope
--> $DIR/ice-type-mismatch-when-copying-112824.rs:5:24
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,12 @@ error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.rs:96:12
|
LL | fn bar(_: &'a Trait) {}
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'a` here: `<'a>`
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | fn bar<'a>(_: &'a Trait) {}
| ++++

error[E0106]: missing lifetime specifier
--> $DIR/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.rs:110:13
Expand Down Expand Up @@ -171,9 +174,12 @@ error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.rs:122:17
|
LL | fn kitten() -> &'a Trait {
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'a` here: `<'a>`
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | fn kitten<'a>() -> &'a Trait {
| ++++

error[E0106]: missing lifetime specifier
--> $DIR/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.rs:133:16
Expand Down
16 changes: 11 additions & 5 deletions tests/ui/error-codes/E0261.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/E0261.rs:1:12
|
LL | fn foo(x: &'a str) { }
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'a` here: `<'a>`
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | fn foo<'a>(x: &'a str) { }
| ++++

error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/E0261.rs:5:9
|
LL | struct Foo {
| - help: consider introducing lifetime `'a` here: `<'a>`
LL | x: &'a str,
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | struct Foo<'a> {
| ++++

error: aborting due to 2 previous errors

Expand Down
9 changes: 6 additions & 3 deletions tests/ui/generics/generic-extern-lifetime.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/generic-extern-lifetime.rs:6:26
|
LL | pub fn life2<'b>(x: &'a i32, y: &'b i32);
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'a` here: `'a,`
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | pub fn life2<'a, 'b>(x: &'a i32, y: &'b i32);
| +++

error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/generic-extern-lifetime.rs:8:37
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/impl-block-params-declared-in-wrong-spot-issue-113073.rs:7:13
|
LL | impl Foo<T: 'a + Default> for u8 {}
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'a` here: `<'a>`
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | impl<'a> Foo<T: 'a + Default> for u8 {}
| ++++

error[E0229]: associated item constraints are not allowed here
--> $DIR/impl-block-params-declared-in-wrong-spot-issue-113073.rs:3:10
Expand Down
9 changes: 6 additions & 3 deletions tests/ui/impl-trait/precise-capturing/bad-lifetimes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ error[E0261]: use of undeclared lifetime name `'missing`
--> $DIR/bad-lifetimes.rs:7:37
|
LL | fn missing_lt() -> impl Sized + use<'missing> {}
| - ^^^^^^^^ undeclared lifetime
| |
| help: consider introducing lifetime `'missing` here: `<'missing>`
| ^^^^^^^^ undeclared lifetime
|
help: consider introducing lifetime `'missing` here
|
LL | fn missing_lt<'missing>() -> impl Sized + use<'missing> {}
| ++++++++++

error: expected lifetime parameter in `use<...>` precise captures list, found `'static`
--> $DIR/bad-lifetimes.rs:4:36
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ error[E0261]: use of undeclared lifetime name `'q`
--> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:14:21
|
LL | impl<'static> Query<'q> {
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'q` here: `'q,`
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'q` here
|
LL | impl<'q, 'static> Query<'q> {
| +++

error[E0392]: lifetime parameter `'q` is never used
--> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:11:14
Expand Down
25 changes: 18 additions & 7 deletions tests/ui/inference/issue-107090.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,23 @@ error[E0261]: use of undeclared lifetime name `'b`
--> $DIR/issue-107090.rs:11:47
|
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'b` here: `'b,`
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'b` here
|
LL | impl<'b, 'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
| +++

error[E0261]: use of undeclared lifetime name `'out`
--> $DIR/issue-107090.rs:11:67
|
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
| - help: consider introducing lifetime `'out` here: `'out,` ^^^^ undeclared lifetime
| ^^^^ undeclared lifetime
|
help: consider introducing lifetime `'out` here
|
LL | impl<'out, 'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
| +++++

error[E0261]: use of undeclared lifetime name `'out`
--> $DIR/issue-107090.rs:14:49
Expand All @@ -62,9 +70,12 @@ error[E0261]: use of undeclared lifetime name `'short`
--> $DIR/issue-107090.rs:20:68
|
LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T {
| - ^^^^^^ undeclared lifetime
| |
| help: consider introducing lifetime `'short` here: `'short,`
| ^^^^^^ undeclared lifetime
|
help: consider introducing lifetime `'short` here
|
LL | fn badboi<'short, 'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T {
| +++++++

error: aborting due to 6 previous errors

Expand Down
9 changes: 6 additions & 3 deletions tests/ui/lifetimes/issue-107988.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ error[E0261]: use of undeclared lifetime name `'tcx`
--> $DIR/issue-107988.rs:7:52
|
LL | impl<T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
| - ^^^^ undeclared lifetime
| |
| help: consider introducing lifetime `'tcx` here: `'tcx,`
| ^^^^ undeclared lifetime
|
help: consider introducing lifetime `'tcx` here
|
LL | impl<'tcx, T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
| +++++

error[E0261]: use of undeclared lifetime name `'tcx`
--> $DIR/issue-107988.rs:7:30
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
error[E0261]: use of undeclared lifetime name `'b`
--> $DIR/undeclared-lifetime-used-in-debug-macro-issue-70152.rs:3:9
|
LL | struct Test {
| - help: consider introducing lifetime `'b` here: `<'b>`
LL | a: &'b str,
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'b` here
|
LL | struct Test<'b> {
| ++++

error[E0261]: use of undeclared lifetime name `'b`
--> $DIR/undeclared-lifetime-used-in-debug-macro-issue-70152.rs:3:9
|
LL | #[derive(Eq, PartialEq)]
| -- lifetime `'b` is missing in item created through this procedural macro
LL | struct Test {
| - help: consider introducing lifetime `'b` here: `<'b>`
LL | a: &'b str,
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'b` here
|
LL | struct Test<'b> {
| ++++

error[E0261]: use of undeclared lifetime name `'b`
--> $DIR/undeclared-lifetime-used-in-debug-macro-issue-70152.rs:13:13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ error[E0261]: use of undeclared lifetime name `'missing`
--> $DIR/dont-ice-on-object-lookup-w-error-region.rs:6:20
|
LL | fn project(x: Pin<&'missing mut dyn Future<Output = ()>>) {
| - ^^^^^^^^ undeclared lifetime
| |
| help: consider introducing lifetime `'missing` here: `<'missing>`
| ^^^^^^^^ undeclared lifetime
|
help: consider introducing lifetime `'missing` here
|
LL | fn project<'missing>(x: Pin<&'missing mut dyn Future<Output = ()>>) {
| ++++++++++

error: aborting due to 1 previous error

Expand Down
Loading
Loading