Skip to content

Commit 72dc29c

Browse files
committed
Handle allow(elided_lifetimes_in_paths).
1 parent c07a6d2 commit 72dc29c

File tree

4 files changed

+45
-32
lines changed

4 files changed

+45
-32
lines changed

compiler/rustc_resolve/src/late/diagnostics.rs

+28-31
Original file line numberDiff line numberDiff line change
@@ -1951,38 +1951,35 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
19511951
}
19521952

19531953
crate fn report_elided_lifetime_in_ty(&self, lifetime_refs: &[&hir::Lifetime]) {
1954-
let missing_lifetimes = lifetime_refs
1955-
.iter()
1956-
.filter(|a| matches!(a, hir::Lifetime { name: hir::LifetimeName::ImplicitMissing, .. }))
1957-
.count();
1958-
1959-
if missing_lifetimes > 0 {
1960-
let mut spans: Vec<_> = lifetime_refs.iter().map(|lt| lt.span).collect();
1961-
spans.sort();
1962-
let mut spans_dedup = spans.clone();
1963-
spans_dedup.dedup();
1964-
let spans_with_counts: Vec<_> = spans_dedup
1965-
.into_iter()
1966-
.map(|sp| (sp, spans.iter().filter(|nsp| *nsp == &sp).count()))
1967-
.collect();
1954+
let Some(missing_lifetime) = lifetime_refs.iter().find(|lt| {
1955+
lt.name == hir::LifetimeName::ImplicitMissing
1956+
}) else { return };
1957+
1958+
let mut spans: Vec<_> = lifetime_refs.iter().map(|lt| lt.span).collect();
1959+
spans.sort();
1960+
let mut spans_dedup = spans.clone();
1961+
spans_dedup.dedup();
1962+
let spans_with_counts: Vec<_> = spans_dedup
1963+
.into_iter()
1964+
.map(|sp| (sp, spans.iter().filter(|nsp| *nsp == &sp).count()))
1965+
.collect();
19681966

1969-
self.tcx.struct_span_lint_hir(
1970-
rustc_session::lint::builtin::ELIDED_LIFETIMES_IN_PATHS,
1971-
hir::CRATE_HIR_ID,
1972-
spans,
1973-
|lint| {
1974-
let mut db = lint.build("hidden lifetime parameters in types are deprecated");
1975-
self.add_missing_lifetime_specifiers_label(
1976-
&mut db,
1977-
spans_with_counts,
1978-
&FxHashSet::from_iter([kw::UnderscoreLifetime]),
1979-
Vec::new(),
1980-
&[],
1981-
);
1982-
db.emit()
1983-
},
1984-
);
1985-
}
1967+
self.tcx.struct_span_lint_hir(
1968+
rustc_session::lint::builtin::ELIDED_LIFETIMES_IN_PATHS,
1969+
missing_lifetime.hir_id,
1970+
spans,
1971+
|lint| {
1972+
let mut db = lint.build("hidden lifetime parameters in types are deprecated");
1973+
self.add_missing_lifetime_specifiers_label(
1974+
&mut db,
1975+
spans_with_counts,
1976+
&FxHashSet::from_iter([kw::UnderscoreLifetime]),
1977+
Vec::new(),
1978+
&[],
1979+
);
1980+
db.emit()
1981+
},
1982+
);
19861983
}
19871984

19881985
// FIXME(const_generics): This patches over an ICE caused by non-'static lifetimes in const

src/test/ui/in-band-lifetimes/elided-lifetimes.fixed

+8
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ macro_rules! anytuple_ref_ty {
9696
}
9797
}
9898

99+
#[allow(elided_lifetimes_in_paths)]
100+
mod blah {
101+
struct Thing<'a>(&'a i32);
102+
struct Bar<T>(T);
103+
104+
fn foo(b: Bar<Thing>) {}
105+
}
106+
99107
fn main() {
100108
let honesty = RefCell::new((4, 'e'));
101109
let loyalty: Ref<'_, (u32, char)> = honesty.borrow();

src/test/ui/in-band-lifetimes/elided-lifetimes.rs

+8
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ macro_rules! anytuple_ref_ty {
9696
}
9797
}
9898

99+
#[allow(elided_lifetimes_in_paths)]
100+
mod blah {
101+
struct Thing<'a>(&'a i32);
102+
struct Bar<T>(T);
103+
104+
fn foo(b: Bar<Thing>) {}
105+
}
106+
99107
fn main() {
100108
let honesty = RefCell::new((4, 'e'));
101109
let loyalty: Ref<(u32, char)> = honesty.borrow();

src/test/ui/in-band-lifetimes/elided-lifetimes.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ LL | fn $fn_name(gift: &str) -> $type_name<'_> {
9090
| ~~~~~~~~~~~~~~
9191

9292
error: hidden lifetime parameters in types are deprecated
93-
--> $DIR/elided-lifetimes.rs:101:22
93+
--> $DIR/elided-lifetimes.rs:109:22
9494
|
9595
LL | let loyalty: Ref<(u32, char)> = honesty.borrow();
9696
| ^ expected named lifetime parameter

0 commit comments

Comments
 (0)