diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2021-03-02 18:24:13 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2021-03-02 18:24:13 -0800 |
| commit | 5824917dbb895a0fec2135d7c448b64317dd0aad (patch) | |
| tree | dc78690c4865cfe94afc7337da2e56012ef7a290 /compiler | |
| parent | 795a934b51cb481ea3cb1cc8c3835a043a9e0102 (diff) | |
| download | rust-5824917dbb895a0fec2135d7c448b64317dd0aad.tar.gz rust-5824917dbb895a0fec2135d7c448b64317dd0aad.zip | |
Account for macros when suggesting adding lifetime
Fix #70152.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_resolve/src/late/diagnostics.rs | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index d60f929cb8f..36707b5938f 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1645,6 +1645,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { ); err.span_label(lifetime_ref.span, "undeclared lifetime"); let mut suggests_in_band = false; + let mut suggest_note = true; for missing in &self.missing_named_lifetime_spots { match missing { MissingLifetimeSpot::Generics(generics) => { @@ -1664,12 +1665,20 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { suggests_in_band = true; (generics.span, format!("<{}>", lifetime_ref)) }; - err.span_suggestion( - span, - &format!("consider introducing lifetime `{}` here", lifetime_ref), - sugg, - Applicability::MaybeIncorrect, - ); + if !span.from_expansion() { + err.span_suggestion( + span, + &format!("consider introducing lifetime `{}` here", lifetime_ref), + sugg, + Applicability::MaybeIncorrect, + ); + } else if suggest_note { + suggest_note = false; // Avoid displaying the same help multiple times. + err.help(&format!( + "consider introducing lifetime `{}` to the item's generics", + lifetime_ref, + )); + } } MissingLifetimeSpot::HigherRanked { span, span_type } => { err.span_suggestion( @@ -1684,7 +1693,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { ); err.note( "for more information on higher-ranked polymorphism, visit \ - https://doc.rust-lang.org/nomicon/hrtb.html", + https://doc.rust-lang.org/nomicon/hrtb.html", ); } _ => {} @@ -1696,7 +1705,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { { err.help( "if you want to experiment with in-band lifetime bindings, \ - add `#![feature(in_band_lifetimes)]` to the crate attributes", + add `#![feature(in_band_lifetimes)]` to the crate attributes", ); } err.emit(); |
