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::source_map::Spanned;
11 use syntax_pos::{self, Span};
14 use rustc::hir::def_id::CrateNum;
17 pub name: Option<Name>,
18 pub attrs: hir::HirVec<ast::Attribute>,
19 pub where_outer: Span,
20 pub where_inner: Span,
21 pub extern_crates: Vec<ExternCrate>,
22 pub imports: Vec<Import>,
23 pub structs: Vec<Struct>,
24 pub unions: Vec<Union>,
26 pub fns: Vec<Function>,
27 pub mods: Vec<Module>,
29 pub typedefs: Vec<Typedef>,
30 pub existentials: Vec<Existential>,
31 pub statics: Vec<Static>,
32 pub constants: Vec<Constant>,
33 pub traits: Vec<Trait>,
34 pub vis: hir::Visibility,
35 pub stab: Option<attr::Stability>,
36 pub depr: Option<attr::Deprecation>,
38 pub foreigns: Vec<hir::ForeignMod>,
39 pub macros: Vec<Macro>,
40 pub proc_macros: Vec<ProcMacro>,
41 pub trait_aliases: Vec<TraitAlias>,
46 pub fn new(name: Option<Name>) -> Module {
49 id: ast::CRATE_NODE_ID,
50 vis: Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Inherited },
53 where_outer: syntax_pos::DUMMY_SP,
54 where_inner: syntax_pos::DUMMY_SP,
55 attrs : hir::HirVec::new(),
56 extern_crates: Vec::new(),
63 typedefs : Vec::new(),
64 existentials: Vec::new(),
66 constants : Vec::new(),
69 foreigns : Vec::new(),
71 proc_macros: Vec::new(),
72 trait_aliases: Vec::new(),
78 #[derive(Debug, Clone, RustcEncodable, RustcDecodable, Copy)]
89 pub vis: hir::Visibility,
90 pub stab: Option<attr::Stability>,
91 pub depr: Option<attr::Deprecation>,
93 pub struct_type: StructType,
95 pub generics: hir::Generics,
96 pub attrs: hir::HirVec<ast::Attribute>,
97 pub fields: hir::HirVec<hir::StructField>,
102 pub vis: hir::Visibility,
103 pub stab: Option<attr::Stability>,
104 pub depr: Option<attr::Deprecation>,
106 pub struct_type: StructType,
108 pub generics: hir::Generics,
109 pub attrs: hir::HirVec<ast::Attribute>,
110 pub fields: hir::HirVec<hir::StructField>,
115 pub vis: hir::Visibility,
116 pub stab: Option<attr::Stability>,
117 pub depr: Option<attr::Deprecation>,
118 pub variants: hir::HirVec<Variant>,
119 pub generics: hir::Generics,
120 pub attrs: hir::HirVec<ast::Attribute>,
128 pub attrs: hir::HirVec<ast::Attribute>,
129 pub def: hir::VariantData,
130 pub stab: Option<attr::Stability>,
131 pub depr: Option<attr::Deprecation>,
135 pub struct Function {
136 pub decl: hir::FnDecl,
137 pub attrs: hir::HirVec<ast::Attribute>,
140 pub vis: hir::Visibility,
141 pub stab: Option<attr::Stability>,
142 pub depr: Option<attr::Deprecation>,
143 pub header: hir::FnHeader,
145 pub generics: hir::Generics,
146 pub body: hir::BodyId,
151 pub gen: hir::Generics,
154 pub attrs: hir::HirVec<ast::Attribute>,
156 pub vis: hir::Visibility,
157 pub stab: Option<attr::Stability>,
158 pub depr: Option<attr::Deprecation>,
161 pub struct Existential {
162 pub exist_ty: hir::ExistTy,
165 pub attrs: hir::HirVec<ast::Attribute>,
167 pub vis: hir::Visibility,
168 pub stab: Option<attr::Stability>,
169 pub depr: Option<attr::Deprecation>,
174 pub type_: P<hir::Ty>,
175 pub mutability: hir::Mutability,
176 pub expr: hir::BodyId,
178 pub attrs: hir::HirVec<ast::Attribute>,
179 pub vis: hir::Visibility,
180 pub stab: Option<attr::Stability>,
181 pub depr: Option<attr::Deprecation>,
186 pub struct Constant {
187 pub type_: P<hir::Ty>,
188 pub expr: hir::BodyId,
190 pub attrs: hir::HirVec<ast::Attribute>,
191 pub vis: hir::Visibility,
192 pub stab: Option<attr::Stability>,
193 pub depr: Option<attr::Deprecation>,
199 pub is_auto: hir::IsAuto,
200 pub unsafety: hir::Unsafety,
202 pub items: hir::HirVec<hir::TraitItem>,
203 pub generics: hir::Generics,
204 pub bounds: hir::HirVec<hir::GenericBound>,
205 pub attrs: hir::HirVec<ast::Attribute>,
208 pub vis: hir::Visibility,
209 pub stab: Option<attr::Stability>,
210 pub depr: Option<attr::Deprecation>,
213 pub struct TraitAlias {
215 pub generics: hir::Generics,
216 pub bounds: hir::HirVec<hir::GenericBound>,
217 pub attrs: hir::HirVec<ast::Attribute>,
220 pub vis: hir::Visibility,
221 pub stab: Option<attr::Stability>,
222 pub depr: Option<attr::Deprecation>,
227 pub unsafety: hir::Unsafety,
228 pub polarity: hir::ImplPolarity,
229 pub defaultness: hir::Defaultness,
230 pub generics: hir::Generics,
231 pub trait_: Option<hir::TraitRef>,
232 pub for_: P<hir::Ty>,
233 pub items: hir::HirVec<hir::ImplItem>,
234 pub attrs: hir::HirVec<ast::Attribute>,
236 pub vis: hir::Visibility,
237 pub stab: Option<attr::Stability>,
238 pub depr: Option<attr::Deprecation>,
242 // For Macro we store the DefId instead of the NodeId, since we also create
243 // these imported macro_rules (which only have a DUMMY_NODE_ID).
246 pub def_id: hir::def_id::DefId,
247 pub attrs: hir::HirVec<ast::Attribute>,
249 pub matchers: hir::HirVec<Span>,
250 pub stab: Option<attr::Stability>,
251 pub depr: Option<attr::Deprecation>,
252 pub imported_from: Option<Name>,
255 pub struct ExternCrate {
258 pub path: Option<String>,
259 pub vis: hir::Visibility,
260 pub attrs: hir::HirVec<ast::Attribute>,
267 pub vis: hir::Visibility,
268 pub attrs: hir::HirVec<ast::Attribute>,
274 pub struct ProcMacro {
278 pub helpers: Vec<Name>,
279 pub attrs: hir::HirVec<ast::Attribute>,
281 pub stab: Option<attr::Stability>,
282 pub depr: Option<attr::Deprecation>,
285 pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
287 hir::VariantData::Struct(..) => Plain,
288 hir::VariantData::Tuple(..) => Tuple,
289 hir::VariantData::Unit(..) => Unit,