Skip to content

Commit 5ae7c98

Browse files
committed
Unify visit_fn
1 parent 5706bd0 commit 5ae7c98

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

compiler/rustc_ast/src/visitors.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ macro_rules! mutability_dependent {
3535
) -> Self::Result {
3636
walk_use_tree(self, use_tree, id)
3737
}
38-
// TODO: hard because of different lifetime bounds
39-
fn visit_fn(&mut self, fk: FnKind<'ast>, _: Span, _: NodeId) -> Self::Result {
40-
walk_fn(self, fk)
41-
}
4238
};
4339
(mut $($lf: lifetime)?) => {
4440
/// Mutable token visiting only exists for the `macro_rules` token marker and should not be
@@ -99,11 +95,6 @@ macro_rules! mutability_dependent {
9995
walk_flat_map_item(self, i)
10096
}
10197

102-
/// `Span` and `NodeId` are mutated at the caller site.
103-
fn visit_fn(&mut self, fk: FnKind<'_>, _: Span, _: NodeId) {
104-
walk_fn(self, fk)
105-
}
106-
10798
fn flat_map_assoc_item(
10899
&mut self,
109100
i: P<AssocItem>,
@@ -211,10 +202,24 @@ macro_rules! mutability_helpers {
211202
};
212203
}
213204

205+
macro_rules! lifetime_helpers {
206+
() => {
207+
macro_rules! fn_kind {
208+
() => { FnKind<'_> }
209+
}
210+
};
211+
($lt: lifetime) => {
212+
macro_rules! fn_kind {
213+
() => { FnKind<$lt> }
214+
}
215+
};
216+
}
217+
214218
macro_rules! make_ast_visitor {
215219
($trait: ident $(<$lt: lifetime>)? $(, $mut: ident)?) => {
216220

217221
mutability_helpers!($($mut)?);
222+
lifetime_helpers!($($lt)?);
218223

219224
macro_rules! result {
220225
() => { result!(Self) };
@@ -315,6 +320,11 @@ macro_rules! make_ast_visitor {
315320
make_visit!{WherePredicate, visit_where_predicate, walk_where_predicate, flat_map_where_predicate, walk_flat_map_where_predicate}
316321
make_visit!{P!(Ty), visit_ty, walk_ty, flat_map_ty, walk_flat_map_ty}
317322

323+
/// `MutVisitor`: `Span` and `NodeId` are mutated at the caller site.
324+
fn visit_fn(&mut self, fk: fn_kind!(), _: Span, _: NodeId) -> result!(){
325+
walk_fn(self, fk)
326+
}
327+
318328
fn visit_param_bound(&mut self, tpb: ref_t!(GenericBound), _ctxt: BoundKind) -> result!() {
319329
walk_param_bound(self, tpb)
320330
}

0 commit comments

Comments
 (0)