From 9c3bf4de5534846b289de626dd4dc78f7dc7d13c Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 18 Oct 2022 20:53:24 +0000 Subject: [PATCH] Consider patterns in fn params in an `Elided(Infer)` lifetime rib. --- compiler/rustc_resolve/src/late.rs | 17 +++++++++++------ .../lifetimes/elided-lifetime-in-param-pat.rs | 11 +++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 src/test/ui/lifetimes/elided-lifetime-in-param-pat.rs diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 776c8ad528c..1675580bd89 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -1853,9 +1853,11 @@ fn resolve_fn_params( 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 { @@ -2827,10 +2829,13 @@ fn check_trait_item( 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"); } } diff --git a/src/test/ui/lifetimes/elided-lifetime-in-param-pat.rs b/src/test/ui/lifetimes/elided-lifetime-in-param-pat.rs new file mode 100644 index 00000000000..c1425fa4243 --- /dev/null +++ b/src/test/ui/lifetimes/elided-lifetime-in-param-pat.rs @@ -0,0 +1,11 @@ +// check-pass + +struct S { + _t: T, +} + +fn f(S::<&i8> { .. }: S<&i8>) {} + +fn main() { + f(S { _t: &42_i8 }); +}