]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/doctree.rs
Get rid of doctree::ForeignItem
[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, symbol::Ident, 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     // (item, renamed)
24     crate items: Vec<(&'hir hir::Item<'hir>, Option<Ident>)>,
25     crate traits: Vec<Trait<'hir>>,
26     crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Ident>)>,
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             foreigns: Vec::new(),
47             macros: Vec::new(),
48             proc_macros: Vec::new(),
49             is_crate: false,
50         }
51     }
52 }
53
54 #[derive(Debug, Clone, Copy)]
55 crate enum StructType {
56     /// A braced struct
57     Plain,
58     /// A tuple struct
59     Tuple,
60     /// A unit struct
61     Unit,
62 }
63
64 crate struct Variant<'hir> {
65     crate name: Symbol,
66     crate id: hir::HirId,
67     crate def: &'hir hir::VariantData<'hir>,
68 }
69
70 crate struct Function<'hir> {
71     crate decl: &'hir hir::FnDecl<'hir>,
72     crate id: hir::HirId,
73     crate name: Symbol,
74     crate header: hir::FnHeader,
75     crate generics: &'hir hir::Generics<'hir>,
76     crate body: hir::BodyId,
77 }
78
79 crate struct Trait<'hir> {
80     crate is_auto: hir::IsAuto,
81     crate unsafety: hir::Unsafety,
82     crate name: Symbol,
83     crate items: Vec<&'hir hir::TraitItem<'hir>>,
84     crate generics: &'hir hir::Generics<'hir>,
85     crate bounds: &'hir [hir::GenericBound<'hir>],
86     crate attrs: &'hir [ast::Attribute],
87     crate id: hir::HirId,
88 }
89
90 // For Macro we store the DefId instead of the NodeId, since we also create
91 // these imported macro_rules (which only have a DUMMY_NODE_ID).
92 crate struct Macro {
93     crate name: Symbol,
94     crate def_id: hir::def_id::DefId,
95     crate matchers: Vec<Span>,
96     crate imported_from: Option<Symbol>,
97 }
98
99 crate struct ExternCrate<'hir> {
100     crate name: Symbol,
101     crate hir_id: HirId,
102     crate cnum: CrateNum,
103     crate path: Option<String>,
104     crate vis: &'hir hir::Visibility<'hir>,
105     crate attrs: &'hir [ast::Attribute],
106     crate span: Span,
107 }
108
109 #[derive(Debug)]
110 crate struct Import<'hir> {
111     crate name: Symbol,
112     crate id: hir::HirId,
113     crate vis: &'hir hir::Visibility<'hir>,
114     crate attrs: &'hir [ast::Attribute],
115     crate path: &'hir hir::Path<'hir>,
116     crate glob: bool,
117     crate span: Span,
118 }
119
120 crate struct ProcMacro {
121     crate name: Symbol,
122     crate id: hir::HirId,
123     crate kind: MacroKind,
124     crate helpers: Vec<Symbol>,
125 }
126
127 crate fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {
128     match *vdata {
129         hir::VariantData::Struct(..) => Plain,
130         hir::VariantData::Tuple(..) => Tuple,
131         hir::VariantData::Unit(..) => Unit,
132     }
133 }