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 pub use self::StructType::*;
6 use rustc_span::hygiene::MacroKind;
7 use rustc_span::{self, Span, Symbol};
10 use rustc_hir::def_id::CrateNum;
12 pub struct Module<'hir> {
13 pub name: Option<Symbol>,
14 pub attrs: &'hir [ast::Attribute],
15 pub where_outer: Span,
16 pub where_inner: Span,
17 pub extern_crates: Vec<ExternCrate<'hir>>,
18 pub imports: Vec<Import<'hir>>,
19 pub structs: Vec<Struct<'hir>>,
20 pub unions: Vec<Union<'hir>>,
21 pub enums: Vec<Enum<'hir>>,
22 pub fns: Vec<Function<'hir>>,
23 pub mods: Vec<Module<'hir>>,
25 pub typedefs: Vec<Typedef<'hir>>,
26 pub opaque_tys: Vec<OpaqueTy<'hir>>,
27 pub statics: Vec<Static<'hir>>,
28 pub constants: Vec<Constant<'hir>>,
29 pub traits: Vec<Trait<'hir>>,
30 pub vis: &'hir hir::Visibility<'hir>,
31 pub impls: Vec<Impl<'hir>>,
32 pub foreigns: Vec<ForeignItem<'hir>>,
33 pub macros: Vec<Macro<'hir>>,
34 pub proc_macros: Vec<ProcMacro<'hir>>,
35 pub trait_aliases: Vec<TraitAlias<'hir>>,
42 attrs: &'hir [ast::Attribute],
43 vis: &'hir hir::Visibility<'hir>,
47 id: hir::CRATE_HIR_ID,
49 where_outer: rustc_span::DUMMY_SP,
50 where_inner: rustc_span::DUMMY_SP,
52 extern_crates: Vec::new(),
60 opaque_tys: Vec::new(),
62 constants: Vec::new(),
67 proc_macros: Vec::new(),
68 trait_aliases: Vec::new(),
74 #[derive(Debug, Clone, Copy)]
84 pub struct Struct<'hir> {
85 pub vis: &'hir hir::Visibility<'hir>,
87 pub struct_type: StructType,
89 pub generics: &'hir hir::Generics<'hir>,
90 pub attrs: &'hir [ast::Attribute],
91 pub fields: &'hir [hir::StructField<'hir>],
95 pub struct Union<'hir> {
96 pub vis: &'hir hir::Visibility<'hir>,
98 pub struct_type: StructType,
100 pub generics: &'hir hir::Generics<'hir>,
101 pub attrs: &'hir [ast::Attribute],
102 pub fields: &'hir [hir::StructField<'hir>],
106 pub struct Enum<'hir> {
107 pub vis: &'hir hir::Visibility<'hir>,
108 pub variants: Vec<Variant<'hir>>,
109 pub generics: &'hir hir::Generics<'hir>,
110 pub attrs: &'hir [ast::Attribute],
116 pub struct Variant<'hir> {
119 pub attrs: &'hir [ast::Attribute],
120 pub def: &'hir hir::VariantData<'hir>,
124 pub struct Function<'hir> {
125 pub decl: &'hir hir::FnDecl<'hir>,
126 pub attrs: &'hir [ast::Attribute],
129 pub vis: &'hir hir::Visibility<'hir>,
130 pub header: hir::FnHeader,
132 pub generics: &'hir hir::Generics<'hir>,
133 pub body: hir::BodyId,
136 pub struct Typedef<'hir> {
137 pub ty: &'hir hir::Ty<'hir>,
138 pub gen: &'hir hir::Generics<'hir>,
141 pub attrs: &'hir [ast::Attribute],
143 pub vis: &'hir hir::Visibility<'hir>,
146 pub struct OpaqueTy<'hir> {
147 pub opaque_ty: &'hir hir::OpaqueTy<'hir>,
150 pub attrs: &'hir [ast::Attribute],
152 pub vis: &'hir hir::Visibility<'hir>,
156 pub struct Static<'hir> {
157 pub type_: &'hir hir::Ty<'hir>,
158 pub mutability: hir::Mutability,
159 pub expr: hir::BodyId,
161 pub attrs: &'hir [ast::Attribute],
162 pub vis: &'hir hir::Visibility<'hir>,
167 pub struct Constant<'hir> {
168 pub type_: &'hir hir::Ty<'hir>,
169 pub expr: hir::BodyId,
171 pub attrs: &'hir [ast::Attribute],
172 pub vis: &'hir hir::Visibility<'hir>,
177 pub struct Trait<'hir> {
178 pub is_auto: hir::IsAuto,
179 pub unsafety: hir::Unsafety,
181 pub items: Vec<&'hir hir::TraitItem<'hir>>,
182 pub generics: &'hir hir::Generics<'hir>,
183 pub bounds: &'hir [hir::GenericBound<'hir>],
184 pub attrs: &'hir [ast::Attribute],
187 pub vis: &'hir hir::Visibility<'hir>,
190 pub struct TraitAlias<'hir> {
192 pub generics: &'hir hir::Generics<'hir>,
193 pub bounds: &'hir [hir::GenericBound<'hir>],
194 pub attrs: &'hir [ast::Attribute],
197 pub vis: &'hir hir::Visibility<'hir>,
201 pub struct Impl<'hir> {
202 pub unsafety: hir::Unsafety,
203 pub polarity: hir::ImplPolarity,
204 pub defaultness: hir::Defaultness,
205 pub constness: hir::Constness,
206 pub generics: &'hir hir::Generics<'hir>,
207 pub trait_: &'hir Option<hir::TraitRef<'hir>>,
208 pub for_: &'hir hir::Ty<'hir>,
209 pub items: Vec<&'hir hir::ImplItem<'hir>>,
210 pub attrs: &'hir [ast::Attribute],
212 pub vis: &'hir hir::Visibility<'hir>,
216 pub struct ForeignItem<'hir> {
217 pub vis: &'hir hir::Visibility<'hir>,
220 pub kind: &'hir hir::ForeignItemKind<'hir>,
221 pub attrs: &'hir [ast::Attribute],
225 // For Macro we store the DefId instead of the NodeId, since we also create
226 // these imported macro_rules (which only have a DUMMY_NODE_ID).
227 pub struct Macro<'hir> {
230 pub def_id: hir::def_id::DefId,
231 pub attrs: &'hir [ast::Attribute],
233 pub matchers: Vec<Span>,
234 pub imported_from: Option<Symbol>,
237 pub struct ExternCrate<'hir> {
240 pub path: Option<String>,
241 pub vis: &'hir hir::Visibility<'hir>,
242 pub attrs: &'hir [ast::Attribute],
246 pub struct Import<'hir> {
249 pub vis: &'hir hir::Visibility<'hir>,
250 pub attrs: &'hir [ast::Attribute],
251 pub path: &'hir hir::Path<'hir>,
256 pub struct ProcMacro<'hir> {
260 pub helpers: Vec<Symbol>,
261 pub attrs: &'hir [ast::Attribute],
265 pub fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {
267 hir::VariantData::Struct(..) => Plain,
268 hir::VariantData::Tuple(..) => Tuple,
269 hir::VariantData::Unit(..) => Unit,