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>,
129 pub attrs: hir::HirVec<ast::Attribute>,
130 pub def: hir::VariantData,
131 pub stab: Option<attr::Stability>,
132 pub depr: Option<attr::Deprecation>,
136 pub struct Function {
137 pub decl: hir::FnDecl,
138 pub attrs: hir::HirVec<ast::Attribute>,
141 pub vis: hir::Visibility,
142 pub stab: Option<attr::Stability>,
143 pub depr: Option<attr::Deprecation>,
144 pub header: hir::FnHeader,
146 pub generics: hir::Generics,
147 pub body: hir::BodyId,
152 pub gen: hir::Generics,
155 pub attrs: hir::HirVec<ast::Attribute>,
157 pub vis: hir::Visibility,
158 pub stab: Option<attr::Stability>,
159 pub depr: Option<attr::Deprecation>,
162 pub struct Existential {
163 pub exist_ty: hir::ExistTy,
166 pub attrs: hir::HirVec<ast::Attribute>,
168 pub vis: hir::Visibility,
169 pub stab: Option<attr::Stability>,
170 pub depr: Option<attr::Deprecation>,
175 pub type_: P<hir::Ty>,
176 pub mutability: hir::Mutability,
177 pub expr: hir::BodyId,
179 pub attrs: hir::HirVec<ast::Attribute>,
180 pub vis: hir::Visibility,
181 pub stab: Option<attr::Stability>,
182 pub depr: Option<attr::Deprecation>,
187 pub struct Constant {
188 pub type_: P<hir::Ty>,
189 pub expr: hir::BodyId,
191 pub attrs: hir::HirVec<ast::Attribute>,
192 pub vis: hir::Visibility,
193 pub stab: Option<attr::Stability>,
194 pub depr: Option<attr::Deprecation>,
200 pub is_auto: hir::IsAuto,
201 pub unsafety: hir::Unsafety,
203 pub items: hir::HirVec<hir::TraitItem>,
204 pub generics: hir::Generics,
205 pub bounds: hir::HirVec<hir::GenericBound>,
206 pub attrs: hir::HirVec<ast::Attribute>,
209 pub vis: hir::Visibility,
210 pub stab: Option<attr::Stability>,
211 pub depr: Option<attr::Deprecation>,
214 pub struct TraitAlias {
216 pub generics: hir::Generics,
217 pub bounds: hir::HirVec<hir::GenericBound>,
218 pub attrs: hir::HirVec<ast::Attribute>,
221 pub vis: hir::Visibility,
222 pub stab: Option<attr::Stability>,
223 pub depr: Option<attr::Deprecation>,
228 pub unsafety: hir::Unsafety,
229 pub polarity: hir::ImplPolarity,
230 pub defaultness: hir::Defaultness,
231 pub generics: hir::Generics,
232 pub trait_: Option<hir::TraitRef>,
233 pub for_: P<hir::Ty>,
234 pub items: hir::HirVec<hir::ImplItem>,
235 pub attrs: hir::HirVec<ast::Attribute>,
237 pub vis: hir::Visibility,
238 pub stab: Option<attr::Stability>,
239 pub depr: Option<attr::Deprecation>,
243 // For Macro we store the DefId instead of the NodeId, since we also create
244 // these imported macro_rules (which only have a DUMMY_NODE_ID).
247 pub def_id: hir::def_id::DefId,
248 pub attrs: hir::HirVec<ast::Attribute>,
250 pub matchers: hir::HirVec<Span>,
251 pub stab: Option<attr::Stability>,
252 pub depr: Option<attr::Deprecation>,
253 pub imported_from: Option<Name>,
256 pub struct ExternCrate {
259 pub path: Option<String>,
260 pub vis: hir::Visibility,
261 pub attrs: hir::HirVec<ast::Attribute>,
268 pub vis: hir::Visibility,
269 pub attrs: hir::HirVec<ast::Attribute>,
275 pub struct ProcMacro {
279 pub helpers: Vec<Name>,
280 pub attrs: hir::HirVec<ast::Attribute>,
282 pub stab: Option<attr::Stability>,
283 pub depr: Option<attr::Deprecation>,
286 pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
288 hir::VariantData::Struct(..) => Plain,
289 hir::VariantData::Tuple(..) => Tuple,
290 hir::VariantData::Unit(..) => Unit,