Remove visit_name
from the AST visitor.
Because the default is empty and it's never overridden. This means `walk_ident` can also be removed, because it does nothing.
This commit is contained in:
parent
ab44b5a408
commit
6dced80b86
2 changed files with 4 additions and 18 deletions
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
use crate::ast::*;
|
use crate::ast::*;
|
||||||
|
|
||||||
use rustc_span::symbol::{Ident, Symbol};
|
use rustc_span::symbol::Ident;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
|
@ -109,12 +109,7 @@ pub enum LifetimeCtxt {
|
||||||
/// to monitor future changes to `Visitor` in case a new method with a
|
/// to monitor future changes to `Visitor` in case a new method with a
|
||||||
/// new default implementation gets introduced.)
|
/// new default implementation gets introduced.)
|
||||||
pub trait Visitor<'ast>: Sized {
|
pub trait Visitor<'ast>: Sized {
|
||||||
fn visit_name(&mut self, _span: Span, _name: Symbol) {
|
fn visit_ident(&mut self, _ident: Ident) {}
|
||||||
// Nothing to do.
|
|
||||||
}
|
|
||||||
fn visit_ident(&mut self, ident: Ident) {
|
|
||||||
walk_ident(self, ident);
|
|
||||||
}
|
|
||||||
fn visit_foreign_item(&mut self, i: &'ast ForeignItem) {
|
fn visit_foreign_item(&mut self, i: &'ast ForeignItem) {
|
||||||
walk_foreign_item(self, i)
|
walk_foreign_item(self, i)
|
||||||
}
|
}
|
||||||
|
@ -267,10 +262,6 @@ macro_rules! walk_list {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_ident<'a, V: Visitor<'a>>(visitor: &mut V, ident: Ident) {
|
|
||||||
visitor.visit_name(ident.span, ident.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) {
|
pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) {
|
||||||
walk_list!(visitor, visit_item, &krate.items);
|
walk_list!(visitor, visit_item, &krate.items);
|
||||||
walk_list!(visitor, visit_attribute, &krate.attrs);
|
walk_list!(visitor, visit_attribute, &krate.attrs);
|
||||||
|
@ -315,11 +306,7 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
|
||||||
visitor.visit_vis(&item.vis);
|
visitor.visit_vis(&item.vis);
|
||||||
visitor.visit_ident(item.ident);
|
visitor.visit_ident(item.ident);
|
||||||
match item.kind {
|
match item.kind {
|
||||||
ItemKind::ExternCrate(orig_name) => {
|
ItemKind::ExternCrate(_) => {}
|
||||||
if let Some(orig_name) = orig_name {
|
|
||||||
visitor.visit_name(item.span, orig_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ItemKind::Use(ref use_tree) => visitor.visit_use_tree(use_tree, item.id, false),
|
ItemKind::Use(ref use_tree) => visitor.visit_use_tree(use_tree, item.id, false),
|
||||||
ItemKind::Static(ref typ, _, ref expr) | ItemKind::Const(_, ref typ, ref expr) => {
|
ItemKind::Static(ref typ, _, ref expr) | ItemKind::Const(_, ref typ, ref expr) => {
|
||||||
visitor.visit_ty(typ);
|
visitor.visit_ty(typ);
|
||||||
|
|
|
@ -16,9 +16,8 @@ impl NodeCounter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ast> Visitor<'ast> for NodeCounter {
|
impl<'ast> Visitor<'ast> for NodeCounter {
|
||||||
fn visit_ident(&mut self, ident: Ident) {
|
fn visit_ident(&mut self, _ident: Ident) {
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
walk_ident(self, ident);
|
|
||||||
}
|
}
|
||||||
fn visit_foreign_item(&mut self, i: &ForeignItem) {
|
fn visit_foreign_item(&mut self, i: &ForeignItem) {
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue