"Fossies" - the Fresh Open Source Software Archive

Member "rustc-1.60.0-src/src/librustdoc/visit.rs" (4 Apr 2022, 2481 Bytes) of package /linux/misc/rustc-1.60.0-src.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Rust source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 use crate::clean::*;
    2 
    3 crate trait DocVisitor: Sized {
    4     fn visit_item(&mut self, item: &Item) {
    5         self.visit_item_recur(item)
    6     }
    7 
    8     /// don't override!
    9     fn visit_inner_recur(&mut self, kind: &ItemKind) {
   10         match kind {
   11             StrippedItem(..) => unreachable!(),
   12             ModuleItem(i) => {
   13                 self.visit_mod(i);
   14                 return;
   15             }
   16             StructItem(i) => i.fields.iter().for_each(|x| self.visit_item(x)),
   17             UnionItem(i) => i.fields.iter().for_each(|x| self.visit_item(x)),
   18             EnumItem(i) => i.variants.iter().for_each(|x| self.visit_item(x)),
   19             TraitItem(i) => i.items.iter().for_each(|x| self.visit_item(x)),
   20             ImplItem(i) => i.items.iter().for_each(|x| self.visit_item(x)),
   21             VariantItem(i) => match i {
   22                 Variant::Struct(j) => j.fields.iter().for_each(|x| self.visit_item(x)),
   23                 Variant::Tuple(fields) => fields.iter().for_each(|x| self.visit_item(x)),
   24                 Variant::CLike => {}
   25             },
   26             ExternCrateItem { src: _ }
   27             | ImportItem(_)
   28             | FunctionItem(_)
   29             | TypedefItem(_, _)
   30             | OpaqueTyItem(_)
   31             | StaticItem(_)
   32             | ConstantItem(_)
   33             | TraitAliasItem(_)
   34             | TyMethodItem(_)
   35             | MethodItem(_, _)
   36             | StructFieldItem(_)
   37             | ForeignFunctionItem(_)
   38             | ForeignStaticItem(_)
   39             | ForeignTypeItem
   40             | MacroItem(_)
   41             | ProcMacroItem(_)
   42             | PrimitiveItem(_)
   43             | AssocConstItem(_, _)
   44             | AssocTypeItem(_, _)
   45             | KeywordItem(_) => {}
   46         }
   47     }
   48 
   49     /// don't override!
   50     fn visit_item_recur(&mut self, item: &Item) {
   51         match &*item.kind {
   52             StrippedItem(i) => self.visit_inner_recur(i),
   53             _ => self.visit_inner_recur(&item.kind),
   54         }
   55     }
   56 
   57     fn visit_mod(&mut self, m: &Module) {
   58         m.items.iter().for_each(|i| self.visit_item(i))
   59     }
   60 
   61     fn visit_crate(&mut self, c: &Crate) {
   62         self.visit_item(&c.module);
   63 
   64         // FIXME: make this a simple by-ref for loop once external_traits is cleaned up
   65         let external_traits = { std::mem::take(&mut *c.external_traits.borrow_mut()) };
   66         for (k, v) in external_traits {
   67             v.trait_.items.iter().for_each(|i| self.visit_item(i));
   68             c.external_traits.borrow_mut().insert(k, v);
   69         }
   70     }
   71 }