Skip to content

Commit dc59c71

Browse files
committed
Split up visit_path so MutVisitor has a path_segment method just like the immutable visitor
1 parent 8979408 commit dc59c71

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

compiler/rustc_ast/src/mut_visit.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ pub trait MutVisitor: Sized {
207207
noop_visit_path(p, self);
208208
}
209209

210+
fn flat_map_path_segment(&mut self, p: PathSegment) -> SmallVec<[PathSegment; 1]> {
211+
noop_flat_map_path_segment(p, self)
212+
}
213+
210214
fn visit_qself(&mut self, qs: &mut Option<P<QSelf>>) {
211215
noop_visit_qself(qs, self);
212216
}
@@ -565,12 +569,19 @@ fn noop_visit_ident<T: MutVisitor>(Ident { name: _, span }: &mut Ident, vis: &mu
565569
vis.visit_span(span);
566570
}
567571

572+
fn noop_flat_map_path_segment<T: MutVisitor>(
573+
mut segment: PathSegment,
574+
vis: &mut T,
575+
) -> SmallVec<[PathSegment; 1]> {
576+
let PathSegment { ident, id, args } = &mut segment;
577+
vis.visit_id(id);
578+
vis.visit_ident(ident);
579+
visit_opt(args, |args| vis.visit_generic_args(args));
580+
smallvec![segment]
581+
}
582+
568583
fn noop_visit_path<T: MutVisitor>(Path { segments, span, tokens }: &mut Path, vis: &mut T) {
569-
for PathSegment { ident, id, args } in segments {
570-
vis.visit_id(id);
571-
vis.visit_ident(ident);
572-
visit_opt(args, |args| vis.visit_generic_args(args));
573-
}
584+
segments.flat_map_in_place(|segment| vis.flat_map_path_segment(segment));
574585
visit_lazy_tts(tokens, vis);
575586
vis.visit_span(span);
576587
}

0 commit comments

Comments
 (0)