1
Fork 0

Keep spans for generics in #[derive(_)] desugaring

Keep the spans for generics coming from a `derive`d Item, so that errors
and suggestions have better detail.

Fix #84003.
This commit is contained in:
Esteban Kuber 2021-11-03 04:19:06 +00:00
parent e5038e2099
commit e70105f971
10 changed files with 312 additions and 53 deletions

View file

@ -1803,7 +1803,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
);
err.span_label(lifetime_ref.span, "undeclared lifetime");
let mut suggests_in_band = false;
let mut suggest_note = true;
let mut suggested_spans = vec![];
for missing in &self.missing_named_lifetime_spots {
match missing {
MissingLifetimeSpot::Generics(generics) => {
@ -1821,6 +1821,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
suggests_in_band = true;
(generics.span, format!("<{}>", lifetime_ref))
};
if suggested_spans.contains(&span) {
continue;
}
suggested_spans.push(span);
if !span.from_expansion() {
err.span_suggestion(
span,
@ -1828,16 +1832,6 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
sugg,
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 } => {