Skip to content

Commit 1ef97a6

Browse files
committed
Unify walk_path
1 parent e3e2836 commit 1ef97a6

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

compiler/rustc_ast/src/visitors.rs

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ macro_rules! make_ast_visitor {
354354
walk_use_tree(self, use_tree, id)
355355
}
356356

357+
/// Id should be visited by the caller
357358
fn visit_path(&mut self, path: ref_t!(Path), _id: NodeId) -> result!() {
358359
walk_path(self, path)
359360
}
@@ -381,6 +382,18 @@ macro_rules! make_ast_visitor {
381382
}
382383
}
383384

385+
macro_rules! visit_lazy_tts {
386+
($vis: expr, $tokens: expr) => {
387+
if_mut_expr!(
388+
visit_lazy_tts($vis, $tokens)
389+
,
390+
// assign to _ to prevent unused_variable warnings
391+
{ let _ = (&$vis, &$tokens); }
392+
);
393+
}
394+
}
395+
396+
384397
// FIXME: should only exist while Visitor::visit_ident
385398
// doesn't receives a reference
386399
macro_rules! visit_ident {
@@ -419,7 +432,12 @@ macro_rules! make_ast_visitor {
419432
try_v!($visitor.$visit(elem));
420433
}
421434
)
422-
}
435+
};
436+
($visitor: expr, $visit: ident, $list: expr) => {
437+
for elem in $list {
438+
try_v!($visitor.$visit(elem));
439+
}
440+
};
423441
}
424442

425443
// TODO: temporary name
@@ -829,8 +847,7 @@ macro_rules! make_ast_visitor {
829847
try_v!(vis.visit_block(els));
830848
}
831849
}
832-
// TODO: Weird
833-
if_mut_expr!(visit_lazy_tts(vis, tokens), { let _ = tokens; });
850+
visit_lazy_tts!(vis, tokens);
834851
visit_o!(colon_sp, |sp| try_v!(visit_span!(vis, sp)));
835852
try_v!(visit_span!(vis, span));
836853
return_result!(V)
@@ -861,6 +878,17 @@ macro_rules! make_ast_visitor {
861878
return_result!(V)
862879
}
863880

881+
pub fn walk_path<$($lt,)? V: $trait$(<$lt>)?>(
882+
vis: &mut V,
883+
path: ref_t!(Path)
884+
) -> result!(V) {
885+
let Path { span, segments, tokens } = path;
886+
visit_list!(vis, visit_path_segment, segments);
887+
visit_lazy_tts!(vis, tokens);
888+
try_v!(visit_span!(vis, span));
889+
return_result!(V)
890+
}
891+
864892
make_walk_flat_map!{Arm, walk_flat_map_arm, visit_arm}
865893
make_walk_flat_map!{Attribute, walk_flat_map_attribute, visit_attribute}
866894
make_walk_flat_map!{ExprField, walk_flat_map_expr_field, visit_expr_field}
@@ -1175,12 +1203,6 @@ pub mod visit {
11751203
V::Result::output()
11761204
}
11771205

1178-
pub fn walk_path<'a, V: Visitor<'a>>(visitor: &mut V, path: &'a Path) -> V::Result {
1179-
let Path { span: _, segments, tokens: _ } = path;
1180-
walk_list!(visitor, visit_path_segment, segments);
1181-
V::Result::output()
1182-
}
1183-
11841206
pub fn walk_generic_arg<'a, V>(visitor: &mut V, generic_arg: &'a GenericArg) -> V::Result
11851207
where
11861208
V: Visitor<'a>,
@@ -1932,14 +1954,6 @@ pub mod mut_visit {
19321954
items.flat_map_in_place(|item| vis.flat_map_foreign_item(item));
19331955
}
19341956

1935-
fn walk_path<T: MutVisitor>(vis: &mut T, Path { segments, span, tokens }: &mut Path) {
1936-
for segment in segments {
1937-
vis.visit_path_segment(segment);
1938-
}
1939-
visit_lazy_tts(vis, tokens);
1940-
vis.visit_span(span);
1941-
}
1942-
19431957
fn walk_generic_arg<T: MutVisitor>(vis: &mut T, arg: &mut GenericArg) {
19441958
match arg {
19451959
GenericArg::Lifetime(lt) => vis.visit_lifetime(lt),

0 commit comments

Comments
 (0)