1 //! This module is used to store stuff from Rust's AST in a more convenient
2 //! manner (and with prettier names) before cleaning.
3 crate use self::StructType::*;
6 use rustc_span::hygiene::MacroKind;
7 use rustc_span::{self, symbol::Ident, Span, Symbol};
10 use rustc_hir::def_id::CrateNum;
13 crate struct Module<'hir> {
14 crate name: Option<Symbol>,
15 crate attrs: &'hir [ast::Attribute],
16 crate where_outer: Span,
17 crate where_inner: Span,
18 crate extern_crates: Vec<ExternCrate<'hir>>,
19 crate imports: Vec<Import<'hir>>,
20 crate fns: Vec<Function<'hir>>,
21 crate mods: Vec<Module<'hir>>,
24 crate items: Vec<(&'hir hir::Item<'hir>, Option<Ident>)>,
25 crate traits: Vec<Trait<'hir>>,
26 crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Ident>)>,
27 crate macros: Vec<Macro>,
28 crate proc_macros: Vec<ProcMacro>,
33 crate fn new(name: Option<Symbol>, attrs: &'hir [ast::Attribute]) -> Module<'hir> {
36 id: hir::CRATE_HIR_ID,
37 where_outer: rustc_span::DUMMY_SP,
38 where_inner: rustc_span::DUMMY_SP,
40 extern_crates: Vec::new(),
48 proc_macros: Vec::new(),
54 #[derive(Debug, Clone, Copy)]
55 crate enum StructType {
64 crate struct Variant<'hir> {
67 crate def: &'hir hir::VariantData<'hir>,
70 crate struct Function<'hir> {
71 crate decl: &'hir hir::FnDecl<'hir>,
74 crate header: hir::FnHeader,
75 crate generics: &'hir hir::Generics<'hir>,
76 crate body: hir::BodyId,
79 crate struct Trait<'hir> {
80 crate is_auto: hir::IsAuto,
81 crate unsafety: hir::Unsafety,
83 crate items: Vec<&'hir hir::TraitItem<'hir>>,
84 crate generics: &'hir hir::Generics<'hir>,
85 crate bounds: &'hir [hir::GenericBound<'hir>],
86 crate attrs: &'hir [ast::Attribute],
90 // For Macro we store the DefId instead of the NodeId, since we also create
91 // these imported macro_rules (which only have a DUMMY_NODE_ID).
94 crate def_id: hir::def_id::DefId,
95 crate matchers: Vec<Span>,
96 crate imported_from: Option<Symbol>,
99 crate struct ExternCrate<'hir> {
102 crate cnum: CrateNum,
103 crate path: Option<String>,
104 crate vis: &'hir hir::Visibility<'hir>,
105 crate attrs: &'hir [ast::Attribute],
110 crate struct Import<'hir> {
112 crate id: hir::HirId,
113 crate vis: &'hir hir::Visibility<'hir>,
114 crate attrs: &'hir [ast::Attribute],
115 crate path: &'hir hir::Path<'hir>,
120 crate struct ProcMacro {
122 crate id: hir::HirId,
123 crate kind: MacroKind,
124 crate helpers: Vec<Symbol>,
127 crate fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {
129 hir::VariantData::Struct(..) => Plain,
130 hir::VariantData::Tuple(..) => Tuple,
131 hir::VariantData::Unit(..) => Unit,