]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/doctree.rs
Get rid of some doctree items
[rust.git] / src / librustdoc / doctree.rs
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 crate use self::StructType::*;
4
5 use rustc_ast as ast;
6 use rustc_span::hygiene::MacroKind;
7 use rustc_span::{self, Span, Symbol};
8
9 use rustc_hir as hir;
10 use rustc_hir::def_id::CrateNum;
11 use rustc_hir::HirId;
12
13 crate struct Module<'hir> {
14     crate name: Option<Symbol>,
15     crate attrs: &'hir [ast::Attribute],
16     crate where_outer: Span,
17     crate where_inner: Span,
18     crate extern_crates: Vec<ExternCrate<'hir>>,
19     crate imports: Vec<Import<'hir>>,
20     crate fns: Vec<Function<'hir>>,
21     crate mods: Vec<Module<'hir>>,
22     crate id: hir::HirId,
23     crate items: Vec<&'hir hir::Item<'hir>>,
24     crate traits: Vec<Trait<'hir>>,
25     crate impls: Vec<Impl<'hir>>,
26     crate foreigns: Vec<ForeignItem<'hir>>,
27     crate macros: Vec<Macro>,
28     crate proc_macros: Vec<ProcMacro>,
29     crate is_crate: bool,
30 }
31
32 impl Module<'hir> {
33     crate fn new(name: Option<Symbol>, attrs: &'hir [ast::Attribute]) -> Module<'hir> {
34         Module {
35             name,
36             id: hir::CRATE_HIR_ID,
37             where_outer: rustc_span::DUMMY_SP,
38             where_inner: rustc_span::DUMMY_SP,
39             attrs,
40             extern_crates: Vec::new(),
41             imports: Vec::new(),
42             fns: Vec::new(),
43             mods: Vec::new(),
44             items: Vec::new(),
45             traits: Vec::new(),
46             impls: Vec::new(),
47             foreigns: Vec::new(),
48             macros: Vec::new(),
49             proc_macros: Vec::new(),
50             is_crate: false,
51         }
52     }
53 }
54
55 #[derive(Debug, Clone, Copy)]
56 crate enum StructType {
57     /// A braced struct
58     Plain,
59     /// A tuple struct
60     Tuple,
61     /// A unit struct
62     Unit,
63 }
64
65 crate struct Variant<'hir> {
66     crate name: Symbol,
67     crate id: hir::HirId,
68     crate def: &'hir hir::VariantData<'hir>,
69 }
70
71 crate struct Function<'hir> {
72     crate decl: &'hir hir::FnDecl<'hir>,
73     crate id: hir::HirId,
74     crate name: Symbol,
75     crate header: hir::FnHeader,
76     crate generics: &'hir hir::Generics<'hir>,
77     crate body: hir::BodyId,
78 }
79
80 crate struct Trait<'hir> {
81     crate is_auto: hir::IsAuto,
82     crate unsafety: hir::Unsafety,
83     crate name: Symbol,
84     crate items: Vec<&'hir hir::TraitItem<'hir>>,
85     crate generics: &'hir hir::Generics<'hir>,
86     crate bounds: &'hir [hir::GenericBound<'hir>],
87     crate attrs: &'hir [ast::Attribute],
88     crate id: hir::HirId,
89 }
90
91 #[derive(Debug)]
92 crate struct Impl<'hir> {
93     crate unsafety: hir::Unsafety,
94     crate polarity: hir::ImplPolarity,
95     crate defaultness: hir::Defaultness,
96     crate constness: hir::Constness,
97     crate generics: &'hir hir::Generics<'hir>,
98     crate trait_: &'hir Option<hir::TraitRef<'hir>>,
99     crate for_: &'hir hir::Ty<'hir>,
100     crate items: Vec<&'hir hir::ImplItem<'hir>>,
101     crate attrs: &'hir [ast::Attribute],
102     crate span: Span,
103     crate vis: &'hir hir::Visibility<'hir>,
104     crate id: hir::HirId,
105 }
106
107 crate struct ForeignItem<'hir> {
108     crate id: hir::HirId,
109     crate name: Symbol,
110     crate kind: &'hir hir::ForeignItemKind<'hir>,
111 }
112
113 // For Macro we store the DefId instead of the NodeId, since we also create
114 // these imported macro_rules (which only have a DUMMY_NODE_ID).
115 crate struct Macro {
116     crate name: Symbol,
117     crate def_id: hir::def_id::DefId,
118     crate matchers: Vec<Span>,
119     crate imported_from: Option<Symbol>,
120 }
121
122 crate struct ExternCrate<'hir> {
123     crate name: Symbol,
124     crate hir_id: HirId,
125     crate cnum: CrateNum,
126     crate path: Option<String>,
127     crate vis: &'hir hir::Visibility<'hir>,
128     crate attrs: &'hir [ast::Attribute],
129     crate span: Span,
130 }
131
132 #[derive(Debug)]
133 crate struct Import<'hir> {
134     crate name: Symbol,
135     crate id: hir::HirId,
136     crate vis: &'hir hir::Visibility<'hir>,
137     crate attrs: &'hir [ast::Attribute],
138     crate path: &'hir hir::Path<'hir>,
139     crate glob: bool,
140     crate span: Span,
141 }
142
143 crate struct ProcMacro {
144     crate name: Symbol,
145     crate id: hir::HirId,
146     crate kind: MacroKind,
147     crate helpers: Vec<Symbol>,
148 }
149
150 crate fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {
151     match *vdata {
152         hir::VariantData::Struct(..) => Plain,
153         hir::VariantData::Tuple(..) => Tuple,
154         hir::VariantData::Unit(..) => Unit,
155     }
156 }