1
Fork 0

Handle allow(elided_lifetimes_in_paths).

This commit is contained in:
Camille GILLOT 2021-10-31 18:39:39 +01:00
commit 72dc29c260
4 changed files with 44 additions and 31 deletions

View file

@ -1951,38 +1951,35 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
} }
crate fn report_elided_lifetime_in_ty(&self, lifetime_refs: &[&hir::Lifetime]) { crate fn report_elided_lifetime_in_ty(&self, lifetime_refs: &[&hir::Lifetime]) {
let missing_lifetimes = lifetime_refs let Some(missing_lifetime) = lifetime_refs.iter().find(|lt| {
.iter() lt.name == hir::LifetimeName::ImplicitMissing
.filter(|a| matches!(a, hir::Lifetime { name: hir::LifetimeName::ImplicitMissing, .. })) }) else { return };
.count();
if missing_lifetimes > 0 { let mut spans: Vec<_> = lifetime_refs.iter().map(|lt| lt.span).collect();
let mut spans: Vec<_> = lifetime_refs.iter().map(|lt| lt.span).collect(); spans.sort();
spans.sort(); let mut spans_dedup = spans.clone();
let mut spans_dedup = spans.clone(); spans_dedup.dedup();
spans_dedup.dedup(); let spans_with_counts: Vec<_> = spans_dedup
let spans_with_counts: Vec<_> = spans_dedup .into_iter()
.into_iter() .map(|sp| (sp, spans.iter().filter(|nsp| *nsp == &sp).count()))
.map(|sp| (sp, spans.iter().filter(|nsp| *nsp == &sp).count())) .collect();
.collect();
self.tcx.struct_span_lint_hir( self.tcx.struct_span_lint_hir(
rustc_session::lint::builtin::ELIDED_LIFETIMES_IN_PATHS, rustc_session::lint::builtin::ELIDED_LIFETIMES_IN_PATHS,
hir::CRATE_HIR_ID, missing_lifetime.hir_id,
spans, spans,
|lint| { |lint| {
let mut db = lint.build("hidden lifetime parameters in types are deprecated"); let mut db = lint.build("hidden lifetime parameters in types are deprecated");
self.add_missing_lifetime_specifiers_label( self.add_missing_lifetime_specifiers_label(
&mut db, &mut db,
spans_with_counts, spans_with_counts,
&FxHashSet::from_iter([kw::UnderscoreLifetime]), &FxHashSet::from_iter([kw::UnderscoreLifetime]),
Vec::new(), Vec::new(),
&[], &[],
); );
db.emit() db.emit()
}, },
); );
}
} }
// FIXME(const_generics): This patches over an ICE caused by non-'static lifetimes in const // FIXME(const_generics): This patches over an ICE caused by non-'static lifetimes in const

View file

@ -96,6 +96,14 @@ macro_rules! anytuple_ref_ty {
} }
} }
#[allow(elided_lifetimes_in_paths)]
mod blah {
struct Thing<'a>(&'a i32);
struct Bar<T>(T);
fn foo(b: Bar<Thing>) {}
}
fn main() { fn main() {
let honesty = RefCell::new((4, 'e')); let honesty = RefCell::new((4, 'e'));
let loyalty: Ref<'_, (u32, char)> = honesty.borrow(); let loyalty: Ref<'_, (u32, char)> = honesty.borrow();

View file

@ -96,6 +96,14 @@ macro_rules! anytuple_ref_ty {
} }
} }
#[allow(elided_lifetimes_in_paths)]
mod blah {
struct Thing<'a>(&'a i32);
struct Bar<T>(T);
fn foo(b: Bar<Thing>) {}
}
fn main() { fn main() {
let honesty = RefCell::new((4, 'e')); let honesty = RefCell::new((4, 'e'));
let loyalty: Ref<(u32, char)> = honesty.borrow(); let loyalty: Ref<(u32, char)> = honesty.borrow();

View file

@ -90,7 +90,7 @@ LL | fn $fn_name(gift: &str) -> $type_name<'_> {
| ~~~~~~~~~~~~~~ | ~~~~~~~~~~~~~~
error: hidden lifetime parameters in types are deprecated error: hidden lifetime parameters in types are deprecated
--> $DIR/elided-lifetimes.rs:101:22 --> $DIR/elided-lifetimes.rs:109:22
| |
LL | let loyalty: Ref<(u32, char)> = honesty.borrow(); LL | let loyalty: Ref<(u32, char)> = honesty.borrow();
| ^ expected named lifetime parameter | ^ expected named lifetime parameter