Skip to content

Commit

Permalink
Consider patterns in fn params in an Elided(Infer) lifetime rib.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Oct 18, 2022
1 parent 4891d57 commit 9c3bf4d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
17 changes: 11 additions & 6 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1853,9 +1853,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
let mut bindings = smallvec![(PatBoundCtx::Product, Default::default())];
for (index, (pat, ty)) in inputs.enumerate() {
debug!(?pat, ?ty);
if let Some(pat) = pat {
self.resolve_pattern(pat, PatternSource::FnParam, &mut bindings);
}
self.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Infer), |this| {
if let Some(pat) = pat {
this.resolve_pattern(pat, PatternSource::FnParam, &mut bindings);
}
});
self.visit_ty(ty);

if let Some(ref candidates) = self.lifetime_elision_candidates {
Expand Down Expand Up @@ -2827,10 +2829,13 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {

fn resolve_params(&mut self, params: &'ast [Param]) {
let mut bindings = smallvec![(PatBoundCtx::Product, Default::default())];
for Param { pat, ty, .. } in params {
self.resolve_pattern(pat, PatternSource::FnParam, &mut bindings);
self.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Infer), |this| {
for Param { pat, .. } in params {
this.resolve_pattern(pat, PatternSource::FnParam, &mut bindings);
}
});
for Param { ty, .. } in params {
self.visit_ty(ty);
debug!("(resolving function / closure) recorded parameter");
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/lifetimes/elided-lifetime-in-param-pat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// check-pass

struct S<T> {
_t: T,
}

fn f(S::<&i8> { .. }: S<&i8>) {}

fn main() {
f(S { _t: &42_i8 });
}

0 comments on commit 9c3bf4d

Please sign in to comment.