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 structs: Vec<Struct<'hir>>,
21 crate unions: Vec<Union<'hir>>,
22 crate enums: Vec<Enum<'hir>>,
23 crate fns: Vec<Function<'hir>>,
24 crate mods: Vec<Module<'hir>>,
26 crate typedefs: Vec<Typedef<'hir>>,
27 crate opaque_tys: Vec<OpaqueTy<'hir>>,
28 crate statics: Vec<Static<'hir>>,
29 crate constants: Vec<Constant<'hir>>,
30 crate traits: Vec<Trait<'hir>>,
31 crate impls: Vec<Impl<'hir>>,
32 crate foreigns: Vec<ForeignItem<'hir>>,
33 crate macros: Vec<Macro>,
34 crate proc_macros: Vec<ProcMacro>,
35 crate trait_aliases: Vec<TraitAlias<'hir>>,
40 crate fn new(name: Option<Symbol>, attrs: &'hir [ast::Attribute]) -> Module<'hir> {
43 id: hir::CRATE_HIR_ID,
44 where_outer: rustc_span::DUMMY_SP,
45 where_inner: rustc_span::DUMMY_SP,
47 extern_crates: Vec::new(),
55 opaque_tys: Vec::new(),
57 constants: Vec::new(),
62 proc_macros: Vec::new(),
63 trait_aliases: Vec::new(),
69 #[derive(Debug, Clone, Copy)]
70 crate enum StructType {
79 crate struct Struct<'hir> {
81 crate struct_type: StructType,
83 crate generics: &'hir hir::Generics<'hir>,
84 crate fields: &'hir [hir::StructField<'hir>],
87 crate struct Union<'hir> {
89 crate struct_type: StructType,
91 crate generics: &'hir hir::Generics<'hir>,
92 crate fields: &'hir [hir::StructField<'hir>],
95 crate struct Enum<'hir> {
96 crate variants: Vec<Variant<'hir>>,
97 crate generics: &'hir hir::Generics<'hir>,
102 crate struct Variant<'hir> {
104 crate id: hir::HirId,
105 crate def: &'hir hir::VariantData<'hir>,
108 crate struct Function<'hir> {
109 crate decl: &'hir hir::FnDecl<'hir>,
110 crate id: hir::HirId,
112 crate header: hir::FnHeader,
113 crate generics: &'hir hir::Generics<'hir>,
114 crate body: hir::BodyId,
117 crate struct Typedef<'hir> {
118 crate ty: &'hir hir::Ty<'hir>,
119 crate gen: &'hir hir::Generics<'hir>,
121 crate id: hir::HirId,
124 crate struct OpaqueTy<'hir> {
125 crate opaque_ty: &'hir hir::OpaqueTy<'hir>,
127 crate id: hir::HirId,
131 crate struct Static<'hir> {
132 crate type_: &'hir hir::Ty<'hir>,
133 crate mutability: hir::Mutability,
134 crate expr: hir::BodyId,
136 crate attrs: &'hir [ast::Attribute],
137 crate vis: &'hir hir::Visibility<'hir>,
138 crate id: hir::HirId,
142 crate struct Constant<'hir> {
143 crate type_: &'hir hir::Ty<'hir>,
144 crate expr: hir::BodyId,
146 crate id: hir::HirId,
149 crate struct Trait<'hir> {
150 crate is_auto: hir::IsAuto,
151 crate unsafety: hir::Unsafety,
153 crate items: Vec<&'hir hir::TraitItem<'hir>>,
154 crate generics: &'hir hir::Generics<'hir>,
155 crate bounds: &'hir [hir::GenericBound<'hir>],
156 crate attrs: &'hir [ast::Attribute],
157 crate id: hir::HirId,
160 crate struct TraitAlias<'hir> {
162 crate generics: &'hir hir::Generics<'hir>,
163 crate bounds: &'hir [hir::GenericBound<'hir>],
164 crate id: hir::HirId,
168 crate struct Impl<'hir> {
169 crate unsafety: hir::Unsafety,
170 crate polarity: hir::ImplPolarity,
171 crate defaultness: hir::Defaultness,
172 crate constness: hir::Constness,
173 crate generics: &'hir hir::Generics<'hir>,
174 crate trait_: &'hir Option<hir::TraitRef<'hir>>,
175 crate for_: &'hir hir::Ty<'hir>,
176 crate items: Vec<&'hir hir::ImplItem<'hir>>,
177 crate attrs: &'hir [ast::Attribute],
179 crate vis: &'hir hir::Visibility<'hir>,
180 crate id: hir::HirId,
183 crate struct ForeignItem<'hir> {
184 crate id: hir::HirId,
186 crate kind: &'hir hir::ForeignItemKind<'hir>,
189 // For Macro we store the DefId instead of the NodeId, since we also create
190 // these imported macro_rules (which only have a DUMMY_NODE_ID).
193 crate def_id: hir::def_id::DefId,
194 crate matchers: Vec<Span>,
195 crate imported_from: Option<Symbol>,
198 crate struct ExternCrate<'hir> {
201 crate cnum: CrateNum,
202 crate path: Option<String>,
203 crate vis: &'hir hir::Visibility<'hir>,
204 crate attrs: &'hir [ast::Attribute],
209 crate struct Import<'hir> {
211 crate id: hir::HirId,
212 crate vis: &'hir hir::Visibility<'hir>,
213 crate attrs: &'hir [ast::Attribute],
214 crate path: &'hir hir::Path<'hir>,
219 crate struct ProcMacro {
221 crate id: hir::HirId,
222 crate kind: MacroKind,
223 crate helpers: Vec<Symbol>,
226 crate fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {
228 hir::VariantData::Struct(..) => Plain,
229 hir::VariantData::Tuple(..) => Tuple,
230 hir::VariantData::Unit(..) => Unit,