]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/doctree.rs
Do not show `::constructor` on tuple struct diagnostics
[rust.git] / src / librustdoc / doctree.rs
1 // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! This module is used to store stuff from Rust's AST in a more convenient
12 //! manner (and with prettier names) before cleaning.
13 pub use self::StructType::*;
14 pub use self::TypeBound::*;
15
16 use syntax::abi;
17 use syntax::ast;
18 use syntax::ast::{Name, NodeId};
19 use syntax::attr;
20 use syntax::ptr::P;
21 use syntax_pos::{self, Span};
22
23 use rustc::hir;
24 use rustc::hir::def_id::CrateNum;
25
26 pub struct Module {
27     pub name: Option<Name>,
28     pub attrs: hir::HirVec<ast::Attribute>,
29     pub where_outer: Span,
30     pub where_inner: Span,
31     pub extern_crates: Vec<ExternCrate>,
32     pub imports: Vec<Import>,
33     pub structs: Vec<Struct>,
34     pub unions: Vec<Union>,
35     pub enums: Vec<Enum>,
36     pub fns: Vec<Function>,
37     pub mods: Vec<Module>,
38     pub id: NodeId,
39     pub typedefs: Vec<Typedef>,
40     pub statics: Vec<Static>,
41     pub constants: Vec<Constant>,
42     pub traits: Vec<Trait>,
43     pub vis: hir::Visibility,
44     pub stab: Option<attr::Stability>,
45     pub depr: Option<attr::Deprecation>,
46     pub impls: Vec<Impl>,
47     pub def_traits: Vec<DefaultImpl>,
48     pub foreigns: Vec<hir::ForeignMod>,
49     pub macros: Vec<Macro>,
50     pub is_crate: bool,
51 }
52
53 impl Module {
54     pub fn new(name: Option<Name>) -> Module {
55         Module {
56             name       : name,
57             id: ast::CRATE_NODE_ID,
58             vis: hir::Inherited,
59             stab: None,
60             depr: None,
61             where_outer: syntax_pos::DUMMY_SP,
62             where_inner: syntax_pos::DUMMY_SP,
63             attrs      : hir::HirVec::new(),
64             extern_crates: Vec::new(),
65             imports    : Vec::new(),
66             structs    : Vec::new(),
67             unions     : Vec::new(),
68             enums      : Vec::new(),
69             fns        : Vec::new(),
70             mods       : Vec::new(),
71             typedefs   : Vec::new(),
72             statics    : Vec::new(),
73             constants  : Vec::new(),
74             traits     : Vec::new(),
75             impls      : Vec::new(),
76             def_traits : Vec::new(),
77             foreigns   : Vec::new(),
78             macros     : Vec::new(),
79             is_crate   : false,
80         }
81     }
82 }
83
84 #[derive(Debug, Clone, RustcEncodable, RustcDecodable, Copy)]
85 pub enum StructType {
86     /// A braced struct
87     Plain,
88     /// A tuple struct
89     Tuple,
90     /// A unit struct
91     Unit,
92 }
93
94 pub enum TypeBound {
95     RegionBound,
96     TraitBound(hir::TraitRef)
97 }
98
99 pub struct Struct {
100     pub vis: hir::Visibility,
101     pub stab: Option<attr::Stability>,
102     pub depr: Option<attr::Deprecation>,
103     pub id: NodeId,
104     pub struct_type: StructType,
105     pub name: Name,
106     pub generics: hir::Generics,
107     pub attrs: hir::HirVec<ast::Attribute>,
108     pub fields: hir::HirVec<hir::StructField>,
109     pub whence: Span,
110 }
111
112 pub struct Union {
113     pub vis: hir::Visibility,
114     pub stab: Option<attr::Stability>,
115     pub depr: Option<attr::Deprecation>,
116     pub id: NodeId,
117     pub struct_type: StructType,
118     pub name: Name,
119     pub generics: hir::Generics,
120     pub attrs: hir::HirVec<ast::Attribute>,
121     pub fields: hir::HirVec<hir::StructField>,
122     pub whence: Span,
123 }
124
125 pub struct Enum {
126     pub vis: hir::Visibility,
127     pub stab: Option<attr::Stability>,
128     pub depr: Option<attr::Deprecation>,
129     pub variants: hir::HirVec<Variant>,
130     pub generics: hir::Generics,
131     pub attrs: hir::HirVec<ast::Attribute>,
132     pub id: NodeId,
133     pub whence: Span,
134     pub name: Name,
135 }
136
137 pub struct Variant {
138     pub name: Name,
139     pub attrs: hir::HirVec<ast::Attribute>,
140     pub def: hir::VariantData,
141     pub stab: Option<attr::Stability>,
142     pub depr: Option<attr::Deprecation>,
143     pub whence: Span,
144 }
145
146 pub struct Function {
147     pub decl: hir::FnDecl,
148     pub attrs: hir::HirVec<ast::Attribute>,
149     pub id: NodeId,
150     pub name: Name,
151     pub vis: hir::Visibility,
152     pub stab: Option<attr::Stability>,
153     pub depr: Option<attr::Deprecation>,
154     pub unsafety: hir::Unsafety,
155     pub constness: hir::Constness,
156     pub whence: Span,
157     pub generics: hir::Generics,
158     pub abi: abi::Abi,
159     pub body: hir::BodyId,
160 }
161
162 pub struct Typedef {
163     pub ty: P<hir::Ty>,
164     pub gen: hir::Generics,
165     pub name: Name,
166     pub id: ast::NodeId,
167     pub attrs: hir::HirVec<ast::Attribute>,
168     pub whence: Span,
169     pub vis: hir::Visibility,
170     pub stab: Option<attr::Stability>,
171     pub depr: Option<attr::Deprecation>,
172 }
173
174 #[derive(Debug)]
175 pub struct Static {
176     pub type_: P<hir::Ty>,
177     pub mutability: hir::Mutability,
178     pub expr: hir::BodyId,
179     pub name: Name,
180     pub attrs: hir::HirVec<ast::Attribute>,
181     pub vis: hir::Visibility,
182     pub stab: Option<attr::Stability>,
183     pub depr: Option<attr::Deprecation>,
184     pub id: ast::NodeId,
185     pub whence: Span,
186 }
187
188 pub struct Constant {
189     pub type_: P<hir::Ty>,
190     pub expr: hir::BodyId,
191     pub name: Name,
192     pub attrs: hir::HirVec<ast::Attribute>,
193     pub vis: hir::Visibility,
194     pub stab: Option<attr::Stability>,
195     pub depr: Option<attr::Deprecation>,
196     pub id: ast::NodeId,
197     pub whence: Span,
198 }
199
200 pub struct Trait {
201     pub unsafety: hir::Unsafety,
202     pub name: Name,
203     pub items: hir::HirVec<hir::TraitItem>,
204     pub generics: hir::Generics,
205     pub bounds: hir::HirVec<hir::TyParamBound>,
206     pub attrs: hir::HirVec<ast::Attribute>,
207     pub id: ast::NodeId,
208     pub whence: Span,
209     pub vis: hir::Visibility,
210     pub stab: Option<attr::Stability>,
211     pub depr: Option<attr::Deprecation>,
212 }
213
214 pub struct Impl {
215     pub unsafety: hir::Unsafety,
216     pub polarity: hir::ImplPolarity,
217     pub generics: hir::Generics,
218     pub trait_: Option<hir::TraitRef>,
219     pub for_: P<hir::Ty>,
220     pub items: hir::HirVec<hir::ImplItem>,
221     pub attrs: hir::HirVec<ast::Attribute>,
222     pub whence: Span,
223     pub vis: hir::Visibility,
224     pub stab: Option<attr::Stability>,
225     pub depr: Option<attr::Deprecation>,
226     pub id: ast::NodeId,
227 }
228
229 pub struct DefaultImpl {
230     pub unsafety: hir::Unsafety,
231     pub trait_: hir::TraitRef,
232     pub id: ast::NodeId,
233     pub attrs: hir::HirVec<ast::Attribute>,
234     pub whence: Span,
235 }
236
237 // For Macro we store the DefId instead of the NodeId, since we also create
238 // these imported macro_rules (which only have a DUMMY_NODE_ID).
239 pub struct Macro {
240     pub name: Name,
241     pub def_id: hir::def_id::DefId,
242     pub attrs: hir::HirVec<ast::Attribute>,
243     pub whence: Span,
244     pub matchers: hir::HirVec<Span>,
245     pub stab: Option<attr::Stability>,
246     pub depr: Option<attr::Deprecation>,
247     pub imported_from: Option<Name>,
248 }
249
250 pub struct ExternCrate {
251     pub name: Name,
252     pub cnum: CrateNum,
253     pub path: Option<String>,
254     pub vis: hir::Visibility,
255     pub attrs: hir::HirVec<ast::Attribute>,
256     pub whence: Span,
257 }
258
259 pub struct Import {
260     pub name: Name,
261     pub id: NodeId,
262     pub vis: hir::Visibility,
263     pub attrs: hir::HirVec<ast::Attribute>,
264     pub path: hir::Path,
265     pub glob: bool,
266     pub whence: Span,
267 }
268
269 pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
270     match *vdata {
271         hir::VariantData::Struct(..) => Plain,
272         hir::VariantData::Tuple(..) => Tuple,
273         hir::VariantData::Unit(..) => Unit,
274     }
275 }