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 syntax::ast::{Name, NodeId};
8 use syntax::ext::base::MacroKind;
10 use syntax_pos::{self, Span};
13 use rustc::hir::def_id::CrateNum;
15 pub struct Module<'hir> {
16 pub name: Option<Name>,
17 pub attrs: &'hir hir::HirVec<ast::Attribute>,
18 pub where_outer: Span,
19 pub where_inner: Span,
20 pub extern_crates: Vec<ExternCrate<'hir>>,
21 pub imports: Vec<Import<'hir>>,
22 pub structs: Vec<Struct<'hir>>,
23 pub unions: Vec<Union<'hir>>,
24 pub enums: Vec<Enum<'hir>>,
25 pub fns: Vec<Function<'hir>>,
26 pub mods: Vec<Module<'hir>>,
28 pub typedefs: Vec<Typedef<'hir>>,
29 pub existentials: Vec<Existential<'hir>>,
30 pub statics: Vec<Static<'hir>>,
31 pub constants: Vec<Constant<'hir>>,
32 pub traits: Vec<Trait<'hir>>,
33 pub vis: &'hir hir::Visibility,
34 pub stab: Option<attr::Stability>,
35 pub depr: Option<attr::Deprecation>,
36 pub impls: Vec<Impl<'hir>>,
37 pub foreigns: Vec<ForeignItem<'hir>>,
38 pub macros: Vec<Macro<'hir>>,
39 pub proc_macros: Vec<ProcMacro<'hir>>,
40 pub trait_aliases: Vec<TraitAlias<'hir>>,
47 attrs: &'hir hir::HirVec<ast::Attribute>,
48 vis: &'hir hir::Visibility,
52 id: ast::CRATE_NODE_ID,
56 where_outer: syntax_pos::DUMMY_SP,
57 where_inner: syntax_pos::DUMMY_SP,
59 extern_crates: Vec::new(),
66 typedefs : Vec::new(),
67 existentials: Vec::new(),
69 constants : Vec::new(),
72 foreigns : Vec::new(),
74 proc_macros: Vec::new(),
75 trait_aliases: Vec::new(),
81 #[derive(Debug, Clone, Copy)]
91 pub struct Struct<'hir> {
92 pub vis: &'hir hir::Visibility,
93 pub stab: Option<attr::Stability>,
94 pub depr: Option<attr::Deprecation>,
96 pub struct_type: StructType,
98 pub generics: &'hir hir::Generics,
99 pub attrs: &'hir hir::HirVec<ast::Attribute>,
100 pub fields: &'hir [hir::StructField],
104 pub struct Union<'hir> {
105 pub vis: &'hir hir::Visibility,
106 pub stab: Option<attr::Stability>,
107 pub depr: Option<attr::Deprecation>,
109 pub struct_type: StructType,
111 pub generics: &'hir hir::Generics,
112 pub attrs: &'hir hir::HirVec<ast::Attribute>,
113 pub fields: &'hir [hir::StructField],
117 pub struct Enum<'hir> {
118 pub vis: &'hir hir::Visibility,
119 pub stab: Option<attr::Stability>,
120 pub depr: Option<attr::Deprecation>,
121 pub variants: Vec<Variant<'hir>>,
122 pub generics: &'hir hir::Generics,
123 pub attrs: &'hir hir::HirVec<ast::Attribute>,
129 pub struct Variant<'hir> {
132 pub attrs: &'hir hir::HirVec<ast::Attribute>,
133 pub def: &'hir hir::VariantData,
134 pub stab: Option<attr::Stability>,
135 pub depr: Option<attr::Deprecation>,
139 pub struct Function<'hir> {
140 pub decl: &'hir hir::FnDecl,
141 pub attrs: &'hir hir::HirVec<ast::Attribute>,
144 pub vis: &'hir hir::Visibility,
145 pub stab: Option<attr::Stability>,
146 pub depr: Option<attr::Deprecation>,
147 pub header: hir::FnHeader,
149 pub generics: &'hir hir::Generics,
150 pub body: hir::BodyId,
153 pub struct Typedef<'hir> {
154 pub ty: &'hir P<hir::Ty>,
155 pub gen: &'hir hir::Generics,
158 pub attrs: &'hir hir::HirVec<ast::Attribute>,
160 pub vis: &'hir hir::Visibility,
161 pub stab: Option<attr::Stability>,
162 pub depr: Option<attr::Deprecation>,
165 pub struct Existential<'hir> {
166 pub exist_ty: &'hir hir::ExistTy,
169 pub attrs: &'hir hir::HirVec<ast::Attribute>,
171 pub vis: &'hir hir::Visibility,
172 pub stab: Option<attr::Stability>,
173 pub depr: Option<attr::Deprecation>,
177 pub struct Static<'hir> {
178 pub type_: &'hir P<hir::Ty>,
179 pub mutability: hir::Mutability,
180 pub expr: hir::BodyId,
182 pub attrs: &'hir hir::HirVec<ast::Attribute>,
183 pub vis: &'hir hir::Visibility,
184 pub stab: Option<attr::Stability>,
185 pub depr: Option<attr::Deprecation>,
190 pub struct Constant<'hir> {
191 pub type_: &'hir P<hir::Ty>,
192 pub expr: hir::BodyId,
194 pub attrs: &'hir hir::HirVec<ast::Attribute>,
195 pub vis: &'hir hir::Visibility,
196 pub stab: Option<attr::Stability>,
197 pub depr: Option<attr::Deprecation>,
202 pub struct Trait<'hir> {
203 pub is_auto: hir::IsAuto,
204 pub unsafety: hir::Unsafety,
206 pub items: Vec<&'hir hir::TraitItem>,
207 pub generics: &'hir hir::Generics,
208 pub bounds: &'hir hir::HirVec<hir::GenericBound>,
209 pub attrs: &'hir hir::HirVec<ast::Attribute>,
212 pub vis: &'hir hir::Visibility,
213 pub stab: Option<attr::Stability>,
214 pub depr: Option<attr::Deprecation>,
217 pub struct TraitAlias<'hir> {
219 pub generics: &'hir hir::Generics,
220 pub bounds: &'hir hir::HirVec<hir::GenericBound>,
221 pub attrs: &'hir hir::HirVec<ast::Attribute>,
224 pub vis: &'hir hir::Visibility,
225 pub stab: Option<attr::Stability>,
226 pub depr: Option<attr::Deprecation>,
230 pub struct Impl<'hir> {
231 pub unsafety: hir::Unsafety,
232 pub polarity: hir::ImplPolarity,
233 pub defaultness: hir::Defaultness,
234 pub generics: &'hir hir::Generics,
235 pub trait_: &'hir Option<hir::TraitRef>,
236 pub for_: &'hir P<hir::Ty>,
237 pub items: Vec<&'hir hir::ImplItem>,
238 pub attrs: &'hir hir::HirVec<ast::Attribute>,
240 pub vis: &'hir hir::Visibility,
241 pub stab: Option<attr::Stability>,
242 pub depr: Option<attr::Deprecation>,
246 pub struct ForeignItem<'hir> {
247 pub vis: &'hir hir::Visibility,
248 pub stab: Option<attr::Stability>,
249 pub depr: Option<attr::Deprecation>,
252 pub kind: &'hir hir::ForeignItemKind,
253 pub attrs: &'hir hir::HirVec<ast::Attribute>,
257 // For Macro we store the DefId instead of the NodeId, since we also create
258 // these imported macro_rules (which only have a DUMMY_NODE_ID).
259 pub struct Macro<'hir> {
261 pub def_id: hir::def_id::DefId,
262 pub attrs: &'hir hir::HirVec<ast::Attribute>,
264 pub matchers: hir::HirVec<Span>,
265 pub stab: Option<attr::Stability>,
266 pub depr: Option<attr::Deprecation>,
267 pub imported_from: Option<Name>,
270 pub struct ExternCrate<'hir> {
273 pub path: Option<String>,
274 pub vis: &'hir hir::Visibility,
275 pub attrs: &'hir hir::HirVec<ast::Attribute>,
279 pub struct Import<'hir> {
282 pub vis: &'hir hir::Visibility,
283 pub attrs: &'hir hir::HirVec<ast::Attribute>,
284 pub path: &'hir hir::Path,
289 pub struct ProcMacro<'hir> {
293 pub helpers: Vec<Name>,
294 pub attrs: &'hir hir::HirVec<ast::Attribute>,
296 pub stab: Option<attr::Stability>,
297 pub depr: Option<attr::Deprecation>,
300 pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
302 hir::VariantData::Struct(..) => Plain,
303 hir::VariantData::Tuple(..) => Tuple,
304 hir::VariantData::Unit(..) => Unit,