mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Auto merge of #106501 - cjgillot:resolved-elided-apit, r=compiler-errors
Correct detection of elided lifetimes in impl-trait. Fixes https://github.com/rust-lang/rust/issues/106338 r? `@compiler-errors` cc `@pnkfelix`
This commit is contained in:
commit
0fb8b72ce4
@ -1195,8 +1195,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
// Fresh lifetimes in APIT used to be allowed in async fns and forbidden in
|
||||
// regular fns.
|
||||
if let Some(hir::PredicateOrigin::ImplTrait) = where_bound_origin
|
||||
&& let hir::LifetimeName::Param(_) = lifetime_ref.res
|
||||
&& lifetime_ref.is_anonymous()
|
||||
&& let hir::LifetimeName::Param(param_id) = lifetime_ref.res
|
||||
&& let Some(generics) = self.tcx.hir().get_generics(self.tcx.local_parent(param_id))
|
||||
&& let Some(param) = generics.params.iter().find(|p| p.def_id == param_id)
|
||||
&& param.is_elided_lifetime()
|
||||
&& let hir::IsAsync::NotAsync = self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id)
|
||||
&& !self.tcx.features().anonymous_lifetime_in_impl_trait
|
||||
{
|
||||
|
@ -60,4 +60,9 @@ mod in_path {
|
||||
//~| ERROR missing lifetime specifier
|
||||
}
|
||||
|
||||
// This must not err, as the `&` actually resolves to `'a`.
|
||||
fn resolved_anonymous<'a, T>(f: impl Fn(&'a str) -> &T) {
|
||||
f("f")
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
Loading…
Reference in New Issue
Block a user