Skip to content

Commit d6cf0df

Browse files
committed
syntax::visit: pub walk_explicit_self so impls can call it as defaults do.
drive-by: added some doc.
1 parent 73a68cd commit d6cf0df

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/libsyntax/visit.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,17 @@ pub fn generics_of_fn(fk: &FnKind) -> Generics {
6161
}
6262
}
6363

64+
/// Each method of the Visitor trait is a hook to be potentially
65+
/// overriden. Each method's default implementation recursively visits
66+
/// the substructure of the input via the corresponding `walk` method;
67+
/// e.g. the `visit_mod` method by default calls `visit::walk_mod`.
68+
///
69+
/// If you want to ensure that your code handles every variant
70+
/// explicitly, you need to override each method. (And you also need
71+
/// to monitor future changes to `Visitor` in case a new method with a
72+
/// new default implementation gets introduced.)
6473
pub trait Visitor<E: Clone> {
74+
6575
fn visit_ident(&mut self, _sp: Span, _ident: Ident, _e: E) {
6676
/*! Visit the idents */
6777
}
@@ -179,9 +189,9 @@ pub fn walk_local<E: Clone, V: Visitor<E>>(visitor: &mut V, local: &Local, env:
179189
}
180190
}
181191

182-
fn walk_explicit_self<E: Clone, V: Visitor<E>>(visitor: &mut V,
183-
explicit_self: &ExplicitSelf,
184-
env: E) {
192+
pub fn walk_explicit_self<E: Clone, V: Visitor<E>>(visitor: &mut V,
193+
explicit_self: &ExplicitSelf,
194+
env: E) {
185195
match explicit_self.node {
186196
SelfStatic | SelfValue | SelfUniq => {}
187197
SelfRegion(ref lifetime, _) => {

0 commit comments

Comments
 (0)