Rollup merge of #82717 - estebank:issue-70152, r=lcnr
Account for macros when suggesting adding lifetime Fix #70152.
This commit is contained in:
commit
c398871341
3 changed files with 77 additions and 8 deletions
|
@ -1645,6 +1645,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
||||||
);
|
);
|
||||||
err.span_label(lifetime_ref.span, "undeclared lifetime");
|
err.span_label(lifetime_ref.span, "undeclared lifetime");
|
||||||
let mut suggests_in_band = false;
|
let mut suggests_in_band = false;
|
||||||
|
let mut suggest_note = true;
|
||||||
for missing in &self.missing_named_lifetime_spots {
|
for missing in &self.missing_named_lifetime_spots {
|
||||||
match missing {
|
match missing {
|
||||||
MissingLifetimeSpot::Generics(generics) => {
|
MissingLifetimeSpot::Generics(generics) => {
|
||||||
|
@ -1664,12 +1665,24 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
||||||
suggests_in_band = true;
|
suggests_in_band = true;
|
||||||
(generics.span, format!("<{}>", lifetime_ref))
|
(generics.span, format!("<{}>", lifetime_ref))
|
||||||
};
|
};
|
||||||
|
if !span.from_expansion() {
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
&format!("consider introducing lifetime `{}` here", lifetime_ref),
|
&format!("consider introducing lifetime `{}` here", lifetime_ref),
|
||||||
sugg,
|
sugg,
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
|
} else if suggest_note {
|
||||||
|
suggest_note = false; // Avoid displaying the same help multiple times.
|
||||||
|
err.span_label(
|
||||||
|
span,
|
||||||
|
&format!(
|
||||||
|
"lifetime `{}` is missing in item created through this procedural \
|
||||||
|
macro",
|
||||||
|
lifetime_ref,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
MissingLifetimeSpot::HigherRanked { span, span_type } => {
|
MissingLifetimeSpot::HigherRanked { span, span_type } => {
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
#[derive(Eq, PartialEq)]
|
||||||
|
struct Test {
|
||||||
|
a: &'b str,
|
||||||
|
//~^ ERROR use of undeclared lifetime name `'b`
|
||||||
|
//~| ERROR use of undeclared lifetime name `'b`
|
||||||
|
}
|
||||||
|
|
||||||
|
trait T {
|
||||||
|
fn foo(&'static self) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl T for Test {
|
||||||
|
fn foo(&'b self) {} //~ ERROR use of undeclared lifetime name `'b`
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,40 @@
|
||||||
|
error[E0261]: use of undeclared lifetime name `'b`
|
||||||
|
--> $DIR/undeclared-lifetime-used-in-debug-macro-issue-70152.rs:13:13
|
||||||
|
|
|
||||||
|
LL | fn foo(&'b self) {}
|
||||||
|
| ^^ undeclared lifetime
|
||||||
|
|
|
||||||
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
|
||||||
|
help: consider introducing lifetime `'b` here
|
||||||
|
|
|
||||||
|
LL | impl<'b> T for Test {
|
||||||
|
| ^^^^
|
||||||
|
help: consider introducing lifetime `'b` here
|
||||||
|
|
|
||||||
|
LL | fn foo<'b>(&'b self) {}
|
||||||
|
| ^^^^
|
||||||
|
|
||||||
|
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: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
|
||||||
|
|
||||||
|
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 {
|
||||||
|
LL | a: &'b str,
|
||||||
|
| ^^ undeclared lifetime
|
||||||
|
|
|
||||||
|
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0261`.
|
Loading…
Add table
Add a link
Reference in a new issue