From f8b1b2bdfb0baf687873af1bbcbb7292bc39a3f7 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 4 Aug 2022 10:10:04 -0300 Subject: [PATCH] Extract record_elided_anchor --- .../src/lifetime_collector.rs | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lifetime_collector.rs b/compiler/rustc_ast_lowering/src/lifetime_collector.rs index 4a7106f8da0..1a9677919d0 100644 --- a/compiler/rustc_ast_lowering/src/lifetime_collector.rs +++ b/compiler/rustc_ast_lowering/src/lifetime_collector.rs @@ -29,6 +29,17 @@ impl<'ast> LifetimeCollectVisitor<'ast> { } } } + + fn record_elided_anchor(&mut self, node_id: NodeId, span: Span) { + if let Some(LifetimeRes::ElidedAnchor { start, end }) = + self.resolver.get_lifetime_res(node_id) + { + for i in start..end { + let lifetime = Lifetime { id: i, ident: Ident::new(kw::UnderscoreLifetime, span) }; + self.record_lifetime_use(lifetime); + } + } + } } impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> { @@ -37,15 +48,7 @@ impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> { } fn visit_path_segment(&mut self, path_span: Span, path_segment: &'ast PathSegment) { - if let Some(LifetimeRes::ElidedAnchor { start, end }) = - self.resolver.get_lifetime_res(path_segment.id) - { - for i in start..end { - let lifetime = - Lifetime { id: i, ident: Ident::new(kw::UnderscoreLifetime, path_span) }; - self.record_lifetime_use(lifetime); - } - } + self.record_elided_anchor(path_segment.id, path_span); visit::walk_path_segment(self, path_span, path_segment); } @@ -65,15 +68,7 @@ impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> { self.current_binders.pop(); } TyKind::Rptr(None, _) => { - if let Some(LifetimeRes::ElidedAnchor { start, end }) = - self.resolver.get_lifetime_res(t.id) - { - for i in start..end { - let lifetime = - Lifetime { id: i, ident: Ident::new(kw::UnderscoreLifetime, t.span) }; - self.record_lifetime_use(lifetime); - } - } + self.record_elided_anchor(t.id, t.span); visit::walk_ty(self, t); } _ => {