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>,
45 pub fn new(name: Option<Name>) -> Module {
48 id: ast::CRATE_NODE_ID,
49 vis: Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Inherited },
52 where_outer: syntax_pos::DUMMY_SP,
53 where_inner: syntax_pos::DUMMY_SP,
54 attrs : hir::HirVec::new(),
55 extern_crates: Vec::new(),
62 typedefs : Vec::new(),
63 existentials: Vec::new(),
65 constants : Vec::new(),
68 foreigns : Vec::new(),
70 proc_macros: Vec::new(),
76 #[derive(Debug, Clone, RustcEncodable, RustcDecodable, Copy)]
87 pub vis: hir::Visibility,
88 pub stab: Option<attr::Stability>,
89 pub depr: Option<attr::Deprecation>,
91 pub struct_type: StructType,
93 pub generics: hir::Generics,
94 pub attrs: hir::HirVec<ast::Attribute>,
95 pub fields: hir::HirVec<hir::StructField>,
100 pub vis: hir::Visibility,
101 pub stab: Option<attr::Stability>,
102 pub depr: Option<attr::Deprecation>,
104 pub struct_type: StructType,
106 pub generics: hir::Generics,
107 pub attrs: hir::HirVec<ast::Attribute>,
108 pub fields: hir::HirVec<hir::StructField>,
113 pub vis: hir::Visibility,
114 pub stab: Option<attr::Stability>,
115 pub depr: Option<attr::Deprecation>,
116 pub variants: hir::HirVec<Variant>,
117 pub generics: hir::Generics,
118 pub attrs: hir::HirVec<ast::Attribute>,
126 pub attrs: hir::HirVec<ast::Attribute>,
127 pub def: hir::VariantData,
128 pub stab: Option<attr::Stability>,
129 pub depr: Option<attr::Deprecation>,
133 pub struct Function {
134 pub decl: hir::FnDecl,
135 pub attrs: hir::HirVec<ast::Attribute>,
138 pub vis: hir::Visibility,
139 pub stab: Option<attr::Stability>,
140 pub depr: Option<attr::Deprecation>,
141 pub header: hir::FnHeader,
143 pub generics: hir::Generics,
144 pub body: hir::BodyId,
149 pub gen: hir::Generics,
152 pub attrs: hir::HirVec<ast::Attribute>,
154 pub vis: hir::Visibility,
155 pub stab: Option<attr::Stability>,
156 pub depr: Option<attr::Deprecation>,
159 pub struct Existential {
160 pub exist_ty: hir::ExistTy,
163 pub attrs: hir::HirVec<ast::Attribute>,
165 pub vis: hir::Visibility,
166 pub stab: Option<attr::Stability>,
167 pub depr: Option<attr::Deprecation>,
172 pub type_: P<hir::Ty>,
173 pub mutability: hir::Mutability,
174 pub expr: hir::BodyId,
176 pub attrs: hir::HirVec<ast::Attribute>,
177 pub vis: hir::Visibility,
178 pub stab: Option<attr::Stability>,
179 pub depr: Option<attr::Deprecation>,
184 pub struct Constant {
185 pub type_: P<hir::Ty>,
186 pub expr: hir::BodyId,
188 pub attrs: hir::HirVec<ast::Attribute>,
189 pub vis: hir::Visibility,
190 pub stab: Option<attr::Stability>,
191 pub depr: Option<attr::Deprecation>,
197 pub is_auto: hir::IsAuto,
198 pub unsafety: hir::Unsafety,
200 pub items: hir::HirVec<hir::TraitItem>,
201 pub generics: hir::Generics,
202 pub bounds: hir::HirVec<hir::GenericBound>,
203 pub attrs: hir::HirVec<ast::Attribute>,
206 pub vis: hir::Visibility,
207 pub stab: Option<attr::Stability>,
208 pub depr: Option<attr::Deprecation>,
213 pub unsafety: hir::Unsafety,
214 pub polarity: hir::ImplPolarity,
215 pub defaultness: hir::Defaultness,
216 pub generics: hir::Generics,
217 pub trait_: Option<hir::TraitRef>,
218 pub for_: P<hir::Ty>,
219 pub items: hir::HirVec<hir::ImplItem>,
220 pub attrs: hir::HirVec<ast::Attribute>,
222 pub vis: hir::Visibility,
223 pub stab: Option<attr::Stability>,
224 pub depr: Option<attr::Deprecation>,
228 // For Macro we store the DefId instead of the NodeId, since we also create
229 // these imported macro_rules (which only have a DUMMY_NODE_ID).
232 pub def_id: hir::def_id::DefId,
233 pub attrs: hir::HirVec<ast::Attribute>,
235 pub matchers: hir::HirVec<Span>,
236 pub stab: Option<attr::Stability>,
237 pub depr: Option<attr::Deprecation>,
238 pub imported_from: Option<Name>,
241 pub struct ExternCrate {
244 pub path: Option<String>,
245 pub vis: hir::Visibility,
246 pub attrs: hir::HirVec<ast::Attribute>,
253 pub vis: hir::Visibility,
254 pub attrs: hir::HirVec<ast::Attribute>,
260 pub struct ProcMacro {
264 pub helpers: Vec<Name>,
265 pub attrs: hir::HirVec<ast::Attribute>,
267 pub stab: Option<attr::Stability>,
268 pub depr: Option<attr::Deprecation>,
271 pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
273 hir::VariantData::Struct(..) => Plain,
274 hir::VariantData::Tuple(..) => Tuple,
275 hir::VariantData::Unit(..) => Unit,