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, 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>>,
23 crate items: Vec<&'hir hir::Item<'hir>>,
24 crate traits: Vec<Trait<'hir>>,
25 crate impls: Vec<Impl<'hir>>,
26 crate foreigns: Vec<ForeignItem<'hir>>,
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(),
49 proc_macros: Vec::new(),
55 #[derive(Debug, Clone, Copy)]
56 crate enum StructType {
65 crate struct Variant<'hir> {
68 crate def: &'hir hir::VariantData<'hir>,
71 crate struct Function<'hir> {
72 crate decl: &'hir hir::FnDecl<'hir>,
75 crate header: hir::FnHeader,
76 crate generics: &'hir hir::Generics<'hir>,
77 crate body: hir::BodyId,
80 crate struct Trait<'hir> {
81 crate is_auto: hir::IsAuto,
82 crate unsafety: hir::Unsafety,
84 crate items: Vec<&'hir hir::TraitItem<'hir>>,
85 crate generics: &'hir hir::Generics<'hir>,
86 crate bounds: &'hir [hir::GenericBound<'hir>],
87 crate attrs: &'hir [ast::Attribute],
92 crate struct Impl<'hir> {
93 crate unsafety: hir::Unsafety,
94 crate polarity: hir::ImplPolarity,
95 crate defaultness: hir::Defaultness,
96 crate constness: hir::Constness,
97 crate generics: &'hir hir::Generics<'hir>,
98 crate trait_: &'hir Option<hir::TraitRef<'hir>>,
99 crate for_: &'hir hir::Ty<'hir>,
100 crate items: Vec<&'hir hir::ImplItem<'hir>>,
101 crate attrs: &'hir [ast::Attribute],
103 crate vis: &'hir hir::Visibility<'hir>,
104 crate id: hir::HirId,
107 crate struct ForeignItem<'hir> {
108 crate id: hir::HirId,
110 crate kind: &'hir hir::ForeignItemKind<'hir>,
113 // For Macro we store the DefId instead of the NodeId, since we also create
114 // these imported macro_rules (which only have a DUMMY_NODE_ID).
117 crate def_id: hir::def_id::DefId,
118 crate matchers: Vec<Span>,
119 crate imported_from: Option<Symbol>,
122 crate struct ExternCrate<'hir> {
125 crate cnum: CrateNum,
126 crate path: Option<String>,
127 crate vis: &'hir hir::Visibility<'hir>,
128 crate attrs: &'hir [ast::Attribute],
133 crate struct Import<'hir> {
135 crate id: hir::HirId,
136 crate vis: &'hir hir::Visibility<'hir>,
137 crate attrs: &'hir [ast::Attribute],
138 crate path: &'hir hir::Path<'hir>,
143 crate struct ProcMacro {
145 crate id: hir::HirId,
146 crate kind: MacroKind,
147 crate helpers: Vec<Symbol>,
150 crate fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {
152 hir::VariantData::Struct(..) => Plain,
153 hir::VariantData::Tuple(..) => Tuple,
154 hir::VariantData::Unit(..) => Unit,