Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5fdce89

Browse files
cjgillotMark-Simulacrum
authored andcommitted
Correct detection of elided lifetimes in impl-trait.
1 parent f099871 commit 5fdce89

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

‎compiler/rustc_hir_analysis/src/collect/lifetimes.rs‎

Lines changed: 4 additions & 2 deletions
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‎

Lines changed: 5 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /