2016-11-04 11:37:39 -04:00
|
|
|
// The visitors in this module collect sizes and counts of the most important
|
|
|
|
// pieces of AST and HIR. The resulting numbers are good approximations but not
|
|
|
|
// completely accurate (some things might be counted twice, others missed).
|
|
|
|
|
2020-02-29 20:37:32 +03:00
|
|
|
use rustc_ast::visit as ast_visit;
|
2022-04-21 10:09:32 +08:00
|
|
|
use rustc_ast::visit::BoundKind;
|
2020-04-27 23:26:11 +05:30
|
|
|
use rustc_ast::{self as ast, AttrId, NodeId};
|
2019-12-24 05:02:53 +01:00
|
|
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
2020-01-05 02:37:57 +01:00
|
|
|
use rustc_hir as hir;
|
2020-01-07 18:12:06 +01:00
|
|
|
use rustc_hir::intravisit as hir_visit;
|
2020-01-05 02:37:57 +01:00
|
|
|
use rustc_hir::HirId;
|
2020-03-29 17:19:48 +02:00
|
|
|
use rustc_middle::hir::map::Map;
|
2021-08-26 20:27:06 +02:00
|
|
|
use rustc_middle::ty::TyCtxt;
|
2020-03-29 17:19:48 +02:00
|
|
|
use rustc_middle::util::common::to_readable_str;
|
2019-12-31 20:15:40 +03:00
|
|
|
use rustc_span::Span;
|
2016-11-04 11:37:39 -04:00
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
|
|
|
enum Id {
|
2019-02-18 12:11:42 +01:00
|
|
|
Node(HirId),
|
2016-11-04 11:37:39 -04:00
|
|
|
Attr(AttrId),
|
|
|
|
None,
|
|
|
|
}
|
|
|
|
|
|
|
|
struct NodeData {
|
|
|
|
count: usize,
|
|
|
|
size: usize,
|
|
|
|
}
|
|
|
|
|
2022-08-11 12:18:21 +10:00
|
|
|
/// This type measures the size of AST and HIR nodes, by implementing the AST
|
|
|
|
/// and HIR `Visitor` traits. But we don't measure every visited type because
|
|
|
|
/// that could cause double counting.
|
|
|
|
///
|
|
|
|
/// For example, `ast::Visitor` has `visit_ident`, but `Ident`s are always
|
|
|
|
/// stored inline within other AST nodes, so we don't implement `visit_ident`
|
|
|
|
/// here. In constrast, we do implement `visit_expr` because `ast::Expr` is
|
|
|
|
/// always stored as `P<ast::Expr>`, and every such expression should be
|
|
|
|
/// measured separately.
|
|
|
|
///
|
|
|
|
/// In general, a `visit_foo` method should be implemented here if the
|
|
|
|
/// corresponding `Foo` type is always stored on its own, e.g.: `P<Foo>`,
|
|
|
|
/// `Box<Foo>`, `Vec<Foo>`, `Box<[Foo]>`.
|
|
|
|
///
|
|
|
|
/// There are some types in the AST and HIR tree that the visitors do not have
|
|
|
|
/// a `visit_*` method for, and so we cannot measure these, which is
|
|
|
|
/// unfortunate.
|
2016-11-04 11:37:39 -04:00
|
|
|
struct StatCollector<'k> {
|
2021-08-26 20:27:06 +02:00
|
|
|
krate: Option<Map<'k>>,
|
2016-11-08 14:02:55 +11:00
|
|
|
data: FxHashMap<&'static str, NodeData>,
|
|
|
|
seen: FxHashSet<Id>,
|
2016-11-04 11:37:39 -04:00
|
|
|
}
|
|
|
|
|
2021-08-26 20:27:06 +02:00
|
|
|
pub fn print_hir_stats(tcx: TyCtxt<'_>) {
|
2016-11-04 11:37:39 -04:00
|
|
|
let mut collector = StatCollector {
|
2021-08-26 20:27:06 +02:00
|
|
|
krate: Some(tcx.hir()),
|
2018-10-16 10:44:26 +02:00
|
|
|
data: FxHashMap::default(),
|
|
|
|
seen: FxHashSet::default(),
|
2016-11-04 11:37:39 -04:00
|
|
|
};
|
2021-09-02 19:22:24 +02:00
|
|
|
tcx.hir().walk_toplevel_module(&mut collector);
|
2021-08-26 20:27:06 +02:00
|
|
|
tcx.hir().walk_attributes(&mut collector);
|
2016-11-04 11:37:39 -04:00
|
|
|
collector.print("HIR STATS");
|
|
|
|
}
|
|
|
|
|
2019-06-21 20:27:44 +02:00
|
|
|
pub fn print_ast_stats(krate: &ast::Crate, title: &str) {
|
2022-08-11 12:18:21 +10:00
|
|
|
use rustc_ast::visit::Visitor;
|
|
|
|
|
2016-11-04 11:37:39 -04:00
|
|
|
let mut collector =
|
2018-10-16 10:44:26 +02:00
|
|
|
StatCollector { krate: None, data: FxHashMap::default(), seen: FxHashSet::default() };
|
2022-08-11 12:18:21 +10:00
|
|
|
collector.visit_crate(krate);
|
2016-11-04 11:37:39 -04:00
|
|
|
collector.print(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'k> StatCollector<'k> {
|
|
|
|
fn record<T>(&mut self, label: &'static str, id: Id, node: &T) {
|
2018-09-07 15:10:16 +02:00
|
|
|
if id != Id::None && !self.seen.insert(id) {
|
|
|
|
return;
|
2016-11-04 11:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
let entry = self.data.entry(label).or_insert(NodeData { count: 0, size: 0 });
|
|
|
|
|
|
|
|
entry.count += 1;
|
2019-02-08 20:40:49 +09:00
|
|
|
entry.size = std::mem::size_of_val(node);
|
2016-11-04 11:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn print(&self, title: &str) {
|
|
|
|
let mut stats: Vec<_> = self.data.iter().collect();
|
|
|
|
|
|
|
|
stats.sort_by_key(|&(_, ref d)| d.count * d.size);
|
|
|
|
|
|
|
|
let mut total_size = 0;
|
|
|
|
|
2021-02-18 14:13:38 +02:00
|
|
|
eprintln!("\n{}\n", title);
|
2016-11-04 11:37:39 -04:00
|
|
|
|
2021-02-18 14:13:38 +02:00
|
|
|
eprintln!("{:<18}{:>18}{:>14}{:>14}", "Name", "Accumulated Size", "Count", "Item Size");
|
|
|
|
eprintln!("----------------------------------------------------------------");
|
2016-11-04 11:37:39 -04:00
|
|
|
|
|
|
|
for (label, data) in stats {
|
2021-02-18 14:13:38 +02:00
|
|
|
eprintln!(
|
2016-11-04 11:37:39 -04:00
|
|
|
"{:<18}{:>18}{:>14}{:>14}",
|
|
|
|
label,
|
|
|
|
to_readable_str(data.count * data.size),
|
|
|
|
to_readable_str(data.count),
|
|
|
|
to_readable_str(data.size)
|
|
|
|
);
|
|
|
|
|
|
|
|
total_size += data.count * data.size;
|
|
|
|
}
|
2021-02-18 14:13:38 +02:00
|
|
|
eprintln!("----------------------------------------------------------------");
|
|
|
|
eprintln!("{:<18}{:>18}\n", "Total", to_readable_str(total_size));
|
2016-11-04 11:37:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
|
2019-11-30 15:08:22 +01:00
|
|
|
fn visit_param(&mut self, param: &'v hir::Param<'v>) {
|
2019-08-27 13:24:32 +02:00
|
|
|
self.record("Param", Id::Node(param.hir_id), param);
|
|
|
|
hir_visit::walk_param(self, param)
|
2019-07-26 19:52:37 -03:00
|
|
|
}
|
|
|
|
|
2016-11-04 11:37:39 -04:00
|
|
|
fn visit_nested_item(&mut self, id: hir::ItemId) {
|
2021-01-30 12:06:04 +01:00
|
|
|
let nested_item = self.krate.unwrap().item(id);
|
2016-11-04 11:37:39 -04:00
|
|
|
self.visit_item(nested_item)
|
|
|
|
}
|
|
|
|
|
2016-12-04 04:21:06 +02:00
|
|
|
fn visit_nested_trait_item(&mut self, trait_item_id: hir::TraitItemId) {
|
|
|
|
let nested_trait_item = self.krate.unwrap().trait_item(trait_item_id);
|
|
|
|
self.visit_trait_item(nested_trait_item)
|
|
|
|
}
|
|
|
|
|
2016-11-09 16:45:26 -05:00
|
|
|
fn visit_nested_impl_item(&mut self, impl_item_id: hir::ImplItemId) {
|
|
|
|
let nested_impl_item = self.krate.unwrap().impl_item(impl_item_id);
|
|
|
|
self.visit_impl_item(nested_impl_item)
|
|
|
|
}
|
|
|
|
|
2021-02-18 00:00:00 +00:00
|
|
|
fn visit_nested_foreign_item(&mut self, id: hir::ForeignItemId) {
|
|
|
|
let nested_foreign_item = self.krate.unwrap().foreign_item(id);
|
|
|
|
self.visit_foreign_item(nested_foreign_item);
|
|
|
|
}
|
|
|
|
|
2017-08-12 19:15:01 +08:00
|
|
|
fn visit_nested_body(&mut self, body_id: hir::BodyId) {
|
|
|
|
let nested_body = self.krate.unwrap().body(body_id);
|
|
|
|
self.visit_body(nested_body)
|
|
|
|
}
|
|
|
|
|
2019-11-28 19:28:50 +01:00
|
|
|
fn visit_item(&mut self, i: &'v hir::Item<'v>) {
|
2021-01-30 17:47:51 +01:00
|
|
|
self.record("Item", Id::Node(i.hir_id()), i);
|
2016-11-04 11:37:39 -04:00
|
|
|
hir_visit::walk_item(self, i)
|
|
|
|
}
|
|
|
|
|
2019-11-28 20:18:29 +01:00
|
|
|
fn visit_foreign_item(&mut self, i: &'v hir::ForeignItem<'v>) {
|
2021-02-01 00:33:38 +01:00
|
|
|
self.record("ForeignItem", Id::Node(i.hir_id()), i);
|
2016-11-04 11:37:39 -04:00
|
|
|
hir_visit::walk_foreign_item(self, i)
|
|
|
|
}
|
2018-09-07 15:10:16 +02:00
|
|
|
|
2019-11-30 15:08:22 +01:00
|
|
|
fn visit_local(&mut self, l: &'v hir::Local<'v>) {
|
2019-02-18 12:11:42 +01:00
|
|
|
self.record("Local", Id::Node(l.hir_id), l);
|
2016-11-04 11:37:39 -04:00
|
|
|
hir_visit::walk_local(self, l)
|
|
|
|
}
|
2018-09-07 15:10:16 +02:00
|
|
|
|
2019-11-30 15:08:22 +01:00
|
|
|
fn visit_block(&mut self, b: &'v hir::Block<'v>) {
|
2019-02-18 12:11:42 +01:00
|
|
|
self.record("Block", Id::Node(b.hir_id), b);
|
2016-11-04 11:37:39 -04:00
|
|
|
hir_visit::walk_block(self, b)
|
|
|
|
}
|
2018-09-07 15:10:16 +02:00
|
|
|
|
2019-11-30 15:08:22 +01:00
|
|
|
fn visit_stmt(&mut self, s: &'v hir::Stmt<'v>) {
|
2019-02-18 12:11:42 +01:00
|
|
|
self.record("Stmt", Id::Node(s.hir_id), s);
|
2016-11-04 11:37:39 -04:00
|
|
|
hir_visit::walk_stmt(self, s)
|
|
|
|
}
|
2018-09-07 15:10:16 +02:00
|
|
|
|
2019-11-30 15:08:22 +01:00
|
|
|
fn visit_arm(&mut self, a: &'v hir::Arm<'v>) {
|
2019-03-30 22:54:29 +00:00
|
|
|
self.record("Arm", Id::Node(a.hir_id), a);
|
2016-11-04 11:37:39 -04:00
|
|
|
hir_visit::walk_arm(self, a)
|
|
|
|
}
|
2018-09-07 15:10:16 +02:00
|
|
|
|
2019-11-30 15:08:22 +01:00
|
|
|
fn visit_pat(&mut self, p: &'v hir::Pat<'v>) {
|
2019-02-18 12:11:42 +01:00
|
|
|
self.record("Pat", Id::Node(p.hir_id), p);
|
2016-11-04 11:37:39 -04:00
|
|
|
hir_visit::walk_pat(self, p)
|
|
|
|
}
|
2018-09-07 15:10:16 +02:00
|
|
|
|
2019-11-30 15:08:22 +01:00
|
|
|
fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
|
2019-02-18 12:11:42 +01:00
|
|
|
self.record("Expr", Id::Node(ex.hir_id), ex);
|
2016-11-04 11:37:39 -04:00
|
|
|
hir_visit::walk_expr(self, ex)
|
|
|
|
}
|
|
|
|
|
2019-12-01 16:08:58 +01:00
|
|
|
fn visit_ty(&mut self, t: &'v hir::Ty<'v>) {
|
2019-02-18 12:11:42 +01:00
|
|
|
self.record("Ty", Id::Node(t.hir_id), t);
|
2016-11-04 11:37:39 -04:00
|
|
|
hir_visit::walk_ty(self, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_fn(
|
|
|
|
&mut self,
|
|
|
|
fk: hir_visit::FnKind<'v>,
|
2019-12-01 16:08:58 +01:00
|
|
|
fd: &'v hir::FnDecl<'v>,
|
2016-12-21 12:32:59 +02:00
|
|
|
b: hir::BodyId,
|
2016-11-04 11:37:39 -04:00
|
|
|
s: Span,
|
2019-02-06 14:16:11 +01:00
|
|
|
id: hir::HirId,
|
|
|
|
) {
|
2016-11-04 11:37:39 -04:00
|
|
|
self.record("FnDecl", Id::None, fd);
|
|
|
|
hir_visit::walk_fn(self, fk, fd, b, s, id)
|
|
|
|
}
|
|
|
|
|
2019-12-01 16:08:58 +01:00
|
|
|
fn visit_where_predicate(&mut self, predicate: &'v hir::WherePredicate<'v>) {
|
2016-11-04 11:37:39 -04:00
|
|
|
self.record("WherePredicate", Id::None, predicate);
|
|
|
|
hir_visit::walk_where_predicate(self, predicate)
|
|
|
|
}
|
|
|
|
|
2019-11-28 21:47:10 +01:00
|
|
|
fn visit_trait_item(&mut self, ti: &'v hir::TraitItem<'v>) {
|
2021-01-30 20:46:50 +01:00
|
|
|
self.record("TraitItem", Id::Node(ti.hir_id()), ti);
|
2016-11-04 11:37:39 -04:00
|
|
|
hir_visit::walk_trait_item(self, ti)
|
|
|
|
}
|
2018-09-07 15:10:16 +02:00
|
|
|
|
2019-11-28 22:16:44 +01:00
|
|
|
fn visit_impl_item(&mut self, ii: &'v hir::ImplItem<'v>) {
|
2021-01-30 23:25:03 +01:00
|
|
|
self.record("ImplItem", Id::Node(ii.hir_id()), ii);
|
2016-11-04 11:37:39 -04:00
|
|
|
hir_visit::walk_impl_item(self, ii)
|
|
|
|
}
|
|
|
|
|
2019-12-01 16:08:58 +01:00
|
|
|
fn visit_param_bound(&mut self, bounds: &'v hir::GenericBound<'v>) {
|
2018-06-14 12:08:58 +01:00
|
|
|
self.record("GenericBound", Id::None, bounds);
|
2018-05-28 15:23:16 +01:00
|
|
|
hir_visit::walk_param_bound(self, bounds)
|
2016-11-04 11:37:39 -04:00
|
|
|
}
|
|
|
|
|
2021-03-16 00:36:07 +03:00
|
|
|
fn visit_field_def(&mut self, s: &'v hir::FieldDef<'v>) {
|
|
|
|
self.record("FieldDef", Id::Node(s.hir_id), s);
|
|
|
|
hir_visit::walk_field_def(self, s)
|
2016-11-04 11:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_variant(
|
|
|
|
&mut self,
|
2019-11-29 09:26:18 +01:00
|
|
|
v: &'v hir::Variant<'v>,
|
2019-12-01 16:08:58 +01:00
|
|
|
g: &'v hir::Generics<'v>,
|
2019-02-06 14:16:11 +01:00
|
|
|
item_id: hir::HirId,
|
|
|
|
) {
|
2016-11-04 11:37:39 -04:00
|
|
|
self.record("Variant", Id::None, v);
|
|
|
|
hir_visit::walk_variant(self, v, g, item_id)
|
|
|
|
}
|
2018-09-07 15:10:16 +02:00
|
|
|
|
2016-11-04 11:37:39 -04:00
|
|
|
fn visit_lifetime(&mut self, lifetime: &'v hir::Lifetime) {
|
2019-02-18 12:11:42 +01:00
|
|
|
self.record("Lifetime", Id::Node(lifetime.hir_id), lifetime);
|
2016-11-04 11:37:39 -04:00
|
|
|
hir_visit::walk_lifetime(self, lifetime)
|
|
|
|
}
|
2018-09-07 15:10:16 +02:00
|
|
|
|
2019-12-01 16:08:58 +01:00
|
|
|
fn visit_qpath(&mut self, qpath: &'v hir::QPath<'v>, id: hir::HirId, span: Span) {
|
2016-10-27 05:17:42 +03:00
|
|
|
self.record("QPath", Id::None, qpath);
|
|
|
|
hir_visit::walk_qpath(self, qpath, id, span)
|
|
|
|
}
|
2018-09-07 15:10:16 +02:00
|
|
|
|
2019-12-01 16:08:58 +01:00
|
|
|
fn visit_path(&mut self, path: &'v hir::Path<'v>, _id: hir::HirId) {
|
2016-11-04 11:37:39 -04:00
|
|
|
self.record("Path", Id::None, path);
|
|
|
|
hir_visit::walk_path(self, path)
|
|
|
|
}
|
2018-09-07 15:10:16 +02:00
|
|
|
|
2022-08-11 12:18:21 +10:00
|
|
|
// `PathSegment` has one inline use (in `ast::ExprKind::MethodCall`) and
|
|
|
|
// one non-inline use (in `Path::segments`). The latter case is more common
|
|
|
|
// than the former case, so we implement this visitor and tolerate the
|
|
|
|
// double counting in the former case.
|
2019-12-01 16:08:58 +01:00
|
|
|
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v hir::PathSegment<'v>) {
|
2016-11-04 11:37:39 -04:00
|
|
|
self.record("PathSegment", Id::None, path_segment);
|
|
|
|
hir_visit::walk_path_segment(self, path_span, path_segment)
|
|
|
|
}
|
2018-09-07 15:10:16 +02:00
|
|
|
|
2019-12-01 16:08:58 +01:00
|
|
|
fn visit_assoc_type_binding(&mut self, type_binding: &'v hir::TypeBinding<'v>) {
|
2019-02-18 12:11:42 +01:00
|
|
|
self.record("TypeBinding", Id::Node(type_binding.hir_id), type_binding);
|
2016-11-04 11:37:39 -04:00
|
|
|
hir_visit::walk_assoc_type_binding(self, type_binding)
|
|
|
|
}
|
2018-09-07 15:10:16 +02:00
|
|
|
|
2022-06-16 07:54:03 +10:00
|
|
|
fn visit_attribute(&mut self, attr: &'v ast::Attribute) {
|
2016-11-14 12:00:25 +00:00
|
|
|
self.record("Attribute", Id::Attr(attr.id), attr);
|
2016-11-04 11:37:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 11:26:52 +01:00
|
|
|
impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
|
|
|
|
fn visit_foreign_item(&mut self, i: &'v ast::ForeignItem) {
|
2016-11-04 11:37:39 -04:00
|
|
|
self.record("ForeignItem", Id::None, i);
|
|
|
|
ast_visit::walk_foreign_item(self, i)
|
|
|
|
}
|
|
|
|
|
2016-12-06 11:26:52 +01:00
|
|
|
fn visit_item(&mut self, i: &'v ast::Item) {
|
2016-11-04 11:37:39 -04:00
|
|
|
self.record("Item", Id::None, i);
|
|
|
|
ast_visit::walk_item(self, i)
|
|
|
|
}
|
|
|
|
|
2016-12-06 11:26:52 +01:00
|
|
|
fn visit_local(&mut self, l: &'v ast::Local) {
|
2016-11-04 11:37:39 -04:00
|
|
|
self.record("Local", Id::None, l);
|
|
|
|
ast_visit::walk_local(self, l)
|
|
|
|
}
|
|
|
|
|
2016-12-06 11:26:52 +01:00
|
|
|
fn visit_block(&mut self, b: &'v ast::Block) {
|
2016-11-04 11:37:39 -04:00
|
|
|
self.record("Block", Id::None, b);
|
|
|
|
ast_visit::walk_block(self, b)
|
|
|
|
}
|
|
|
|
|
2016-12-06 11:26:52 +01:00
|
|
|
fn visit_stmt(&mut self, s: &'v ast::Stmt) {
|
2016-11-04 11:37:39 -04:00
|
|
|
self.record("Stmt", Id::None, s);
|
|
|
|
ast_visit::walk_stmt(self, s)
|
|
|
|
}
|
|
|
|
|
2022-08-11 12:18:21 +10:00
|
|
|
fn visit_param(&mut self, p: &'v ast::Param) {
|
|
|
|
self.record("Param", Id::None, p);
|
|
|
|
ast_visit::walk_param(self, p)
|
|
|
|
}
|
|
|
|
|
2016-12-06 11:26:52 +01:00
|
|
|
fn visit_arm(&mut self, a: &'v ast::Arm) {
|
2016-11-04 11:37:39 -04:00
|
|
|
self.record("Arm", Id::None, a);
|
|
|
|
ast_visit::walk_arm(self, a)
|
|
|
|
}
|
|
|
|
|
2016-12-06 11:26:52 +01:00
|
|
|
fn visit_pat(&mut self, p: &'v ast::Pat) {
|
2016-11-04 11:37:39 -04:00
|
|
|
self.record("Pat", Id::None, p);
|
|
|
|
ast_visit::walk_pat(self, p)
|
|
|
|
}
|
|
|
|
|
2016-12-06 11:26:52 +01:00
|
|
|
fn visit_expr(&mut self, ex: &'v ast::Expr) {
|
2016-11-04 11:37:39 -04:00
|
|
|
self.record("Expr", Id::None, ex);
|
|
|
|
ast_visit::walk_expr(self, ex)
|
|
|
|
}
|
|
|
|
|
2016-12-06 11:26:52 +01:00
|
|
|
fn visit_ty(&mut self, t: &'v ast::Ty) {
|
2016-11-04 11:37:39 -04:00
|
|
|
self.record("Ty", Id::None, t);
|
|
|
|
ast_visit::walk_ty(self, t)
|
|
|
|
}
|
|
|
|
|
2022-08-11 12:18:21 +10:00
|
|
|
fn visit_generic_param(&mut self, g: &'v ast::GenericParam) {
|
|
|
|
self.record("GenericParam", Id::None, g);
|
|
|
|
ast_visit::walk_generic_param(self, g)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_where_predicate(&mut self, p: &'v ast::WherePredicate) {
|
|
|
|
self.record("WherePredicate", Id::None, p);
|
|
|
|
ast_visit::walk_where_predicate(self, p)
|
|
|
|
}
|
|
|
|
|
2020-01-30 00:18:54 +01:00
|
|
|
fn visit_fn(&mut self, fk: ast_visit::FnKind<'v>, s: Span, _: NodeId) {
|
|
|
|
self.record("FnDecl", Id::None, fk.decl());
|
|
|
|
ast_visit::walk_fn(self, fk, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_assoc_item(&mut self, item: &'v ast::AssocItem, ctxt: ast_visit::AssocCtxt) {
|
2022-08-11 12:34:52 +10:00
|
|
|
self.record("AssocItem", Id::None, item);
|
2020-01-30 00:18:54 +01:00
|
|
|
ast_visit::walk_assoc_item(self, item, ctxt);
|
2016-11-04 11:37:39 -04:00
|
|
|
}
|
|
|
|
|
2022-04-21 10:09:32 +08:00
|
|
|
fn visit_param_bound(&mut self, bounds: &'v ast::GenericBound, _ctxt: BoundKind) {
|
2018-06-14 12:08:58 +01:00
|
|
|
self.record("GenericBound", Id::None, bounds);
|
2018-05-28 15:23:16 +01:00
|
|
|
ast_visit::walk_param_bound(self, bounds)
|
2016-11-04 11:37:39 -04:00
|
|
|
}
|
|
|
|
|
2021-03-16 00:36:07 +03:00
|
|
|
fn visit_field_def(&mut self, s: &'v ast::FieldDef) {
|
|
|
|
self.record("FieldDef", Id::None, s);
|
|
|
|
ast_visit::walk_field_def(self, s)
|
2016-11-04 11:37:39 -04:00
|
|
|
}
|
|
|
|
|
2019-08-24 13:54:40 -03:00
|
|
|
fn visit_variant(&mut self, v: &'v ast::Variant) {
|
2016-11-04 11:37:39 -04:00
|
|
|
self.record("Variant", Id::None, v);
|
2019-08-24 13:54:40 -03:00
|
|
|
ast_visit::walk_variant(self, v)
|
2016-11-04 11:37:39 -04:00
|
|
|
}
|
|
|
|
|
2022-08-11 12:18:21 +10:00
|
|
|
// `UseTree` has one inline use (in `ast::ItemKind::Use`) and one
|
|
|
|
// non-inline use (in `ast::UseTreeKind::Nested). The former case is more
|
|
|
|
// common, so we don't implement `visit_use_tree` and tolerate the missed
|
|
|
|
// coverage in the latter case.
|
2016-11-04 11:37:39 -04:00
|
|
|
|
2016-12-06 11:26:52 +01:00
|
|
|
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v ast::PathSegment) {
|
2016-11-04 11:37:39 -04:00
|
|
|
self.record("PathSegment", Id::None, path_segment);
|
|
|
|
ast_visit::walk_path_segment(self, path_span, path_segment)
|
|
|
|
}
|
|
|
|
|
2022-08-11 12:18:21 +10:00
|
|
|
// `GenericArgs` has one inline use (in `ast::AssocConstraint::gen_args`) and one
|
|
|
|
// non-inline use (in `ast::PathSegment::args`). The latter case is more
|
|
|
|
// common, so we implement `visit_generic_args` and tolerate the double
|
|
|
|
// counting in the former case.
|
|
|
|
fn visit_generic_args(&mut self, sp: Span, g: &'v ast::GenericArgs) {
|
|
|
|
self.record("GenericArgs", Id::None, g);
|
|
|
|
ast_visit::walk_generic_args(self, sp, g)
|
2016-11-04 11:37:39 -04:00
|
|
|
}
|
|
|
|
|
2016-12-06 11:26:52 +01:00
|
|
|
fn visit_attribute(&mut self, attr: &'v ast::Attribute) {
|
2016-11-04 11:37:39 -04:00
|
|
|
self.record("Attribute", Id::None, attr);
|
2022-08-11 12:18:21 +10:00
|
|
|
ast_visit::walk_attribute(self, attr)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_expr_field(&mut self, f: &'v ast::ExprField) {
|
|
|
|
self.record("ExprField", Id::None, f);
|
|
|
|
ast_visit::walk_expr_field(self, f)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_crate(&mut self, krate: &'v ast::Crate) {
|
|
|
|
self.record("Crate", Id::None, krate);
|
|
|
|
ast_visit::walk_crate(self, krate)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_inline_asm(&mut self, asm: &'v ast::InlineAsm) {
|
|
|
|
self.record("InlineAsm", Id::None, asm);
|
|
|
|
ast_visit::walk_inline_asm(self, asm)
|
2016-11-04 11:37:39 -04:00
|
|
|
}
|
|
|
|
}
|