Skip to content

Commit f8b1b2b

Browse files
committed
Extract record_elided_anchor
1 parent 9f10f58 commit f8b1b2b

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

compiler/rustc_ast_lowering/src/lifetime_collector.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ impl<'ast> LifetimeCollectVisitor<'ast> {
2929
}
3030
}
3131
}
32+
33+
fn record_elided_anchor(&mut self, node_id: NodeId, span: Span) {
34+
if let Some(LifetimeRes::ElidedAnchor { start, end }) =
35+
self.resolver.get_lifetime_res(node_id)
36+
{
37+
for i in start..end {
38+
let lifetime = Lifetime { id: i, ident: Ident::new(kw::UnderscoreLifetime, span) };
39+
self.record_lifetime_use(lifetime);
40+
}
41+
}
42+
}
3243
}
3344

3445
impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> {
@@ -37,15 +48,7 @@ impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> {
3748
}
3849

3950
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'ast PathSegment) {
40-
if let Some(LifetimeRes::ElidedAnchor { start, end }) =
41-
self.resolver.get_lifetime_res(path_segment.id)
42-
{
43-
for i in start..end {
44-
let lifetime =
45-
Lifetime { id: i, ident: Ident::new(kw::UnderscoreLifetime, path_span) };
46-
self.record_lifetime_use(lifetime);
47-
}
48-
}
51+
self.record_elided_anchor(path_segment.id, path_span);
4952
visit::walk_path_segment(self, path_span, path_segment);
5053
}
5154

@@ -65,15 +68,7 @@ impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> {
6568
self.current_binders.pop();
6669
}
6770
TyKind::Rptr(None, _) => {
68-
if let Some(LifetimeRes::ElidedAnchor { start, end }) =
69-
self.resolver.get_lifetime_res(t.id)
70-
{
71-
for i in start..end {
72-
let lifetime =
73-
Lifetime { id: i, ident: Ident::new(kw::UnderscoreLifetime, t.span) };
74-
self.record_lifetime_use(lifetime);
75-
}
76-
}
71+
self.record_elided_anchor(t.id, t.span);
7772
visit::walk_ty(self, t);
7873
}
7974
_ => {

0 commit comments

Comments
 (0)