Skip to content

Commit 0fb8b72

Browse files
committed
Auto merge of rust-lang#106501 - cjgillot:resolved-elided-apit, r=compiler-errors
Correct detection of elided lifetimes in impl-trait. Fixes rust-lang#106338 r? `@compiler-errors` cc `@pnkfelix`
2 parents afe8c45 + de1859f commit 0fb8b72

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

compiler/rustc_hir_analysis/src/collect/lifetimes.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1195,8 +1195,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
11951195
// Fresh lifetimes in APIT used to be allowed in async fns and forbidden in
11961196
// regular fns.
11971197
if let Some(hir::PredicateOrigin::ImplTrait) = where_bound_origin
1198-
&& let hir::LifetimeName::Param(_) = lifetime_ref.res
1199-
&& lifetime_ref.is_anonymous()
1198+
&& let hir::LifetimeName::Param(param_id) = lifetime_ref.res
1199+
&& let Some(generics) = self.tcx.hir().get_generics(self.tcx.local_parent(param_id))
1200+
&& let Some(param) = generics.params.iter().find(|p| p.def_id == param_id)
1201+
&& param.is_elided_lifetime()
12001202
&& let hir::IsAsync::NotAsync = self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id)
12011203
&& !self.tcx.features().anonymous_lifetime_in_impl_trait
12021204
{

src/test/ui/suggestions/impl-trait-missing-lifetime-gated.rs

+5
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,9 @@ mod in_path {
6060
//~| ERROR missing lifetime specifier
6161
}
6262

63+
// This must not err, as the `&` actually resolves to `'a`.
64+
fn resolved_anonymous<'a, T>(f: impl Fn(&'a str) -> &T) {
65+
f("f")
66+
}
67+
6368
fn main() {}

0 commit comments

Comments
 (0)