diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2021-10-31 18:39:39 +0100 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2021-11-30 22:55:07 +0100 |
| commit | 72dc29c260cb6730449ed789c8a0ab4292acb7b0 (patch) | |
| tree | 3bd564f573c52ba1d456aa3e01b8c364cc5100c7 /compiler/rustc_resolve/src | |
| parent | c07a6d2ef025839d0a36754c163899bc311460f6 (diff) | |
| download | rust-72dc29c260cb6730449ed789c8a0ab4292acb7b0.tar.gz rust-72dc29c260cb6730449ed789c8a0ab4292acb7b0.zip | |
Handle `allow(elided_lifetimes_in_paths)`.
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/late/diagnostics.rs | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 2186a9a73c5..d140c2da9bd 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1951,38 +1951,35 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { } crate fn report_elided_lifetime_in_ty(&self, lifetime_refs: &[&hir::Lifetime]) { - let missing_lifetimes = lifetime_refs - .iter() - .filter(|a| matches!(a, hir::Lifetime { name: hir::LifetimeName::ImplicitMissing, .. })) - .count(); - - if missing_lifetimes > 0 { - let mut spans: Vec<_> = lifetime_refs.iter().map(|lt| lt.span).collect(); - spans.sort(); - let mut spans_dedup = spans.clone(); - spans_dedup.dedup(); - let spans_with_counts: Vec<_> = spans_dedup - .into_iter() - .map(|sp| (sp, spans.iter().filter(|nsp| *nsp == &sp).count())) - .collect(); + let Some(missing_lifetime) = lifetime_refs.iter().find(|lt| { + lt.name == hir::LifetimeName::ImplicitMissing + }) else { return }; + + let mut spans: Vec<_> = lifetime_refs.iter().map(|lt| lt.span).collect(); + spans.sort(); + let mut spans_dedup = spans.clone(); + spans_dedup.dedup(); + let spans_with_counts: Vec<_> = spans_dedup + .into_iter() + .map(|sp| (sp, spans.iter().filter(|nsp| *nsp == &sp).count())) + .collect(); - self.tcx.struct_span_lint_hir( - rustc_session::lint::builtin::ELIDED_LIFETIMES_IN_PATHS, - hir::CRATE_HIR_ID, - spans, - |lint| { - let mut db = lint.build("hidden lifetime parameters in types are deprecated"); - self.add_missing_lifetime_specifiers_label( - &mut db, - spans_with_counts, - &FxHashSet::from_iter([kw::UnderscoreLifetime]), - Vec::new(), - &[], - ); - db.emit() - }, - ); - } + self.tcx.struct_span_lint_hir( + rustc_session::lint::builtin::ELIDED_LIFETIMES_IN_PATHS, + missing_lifetime.hir_id, + spans, + |lint| { + let mut db = lint.build("hidden lifetime parameters in types are deprecated"); + self.add_missing_lifetime_specifiers_label( + &mut db, + spans_with_counts, + &FxHashSet::from_iter([kw::UnderscoreLifetime]), + Vec::new(), + &[], + ); + db.emit() + }, + ); } // FIXME(const_generics): This patches over an ICE caused by non-'static lifetimes in const |
