]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/doctree.rs
Get rid of doctree::Function
[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::{self, symbol::Ident, Span, Symbol};
7
8 use rustc_hir as hir;
9 use rustc_hir::def_id::CrateNum;
10 use rustc_hir::HirId;
11
12 crate struct Module<'hir> {
13     crate name: Option<Symbol>,
14     crate attrs: &'hir [ast::Attribute],
15     crate where_outer: Span,
16     crate where_inner: Span,
17     crate extern_crates: Vec<ExternCrate<'hir>>,
18     crate imports: Vec<Import<'hir>>,
19     crate mods: Vec<Module<'hir>>,
20     crate id: hir::HirId,
21     // (item, renamed)
22     crate items: Vec<(&'hir hir::Item<'hir>, Option<Ident>)>,
23     crate traits: Vec<Trait<'hir>>,
24     crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Ident>)>,
25     crate macros: Vec<Macro>,
26     crate is_crate: bool,
27 }
28
29 impl Module<'hir> {
30     crate fn new(name: Option<Symbol>, attrs: &'hir [ast::Attribute]) -> Module<'hir> {
31         Module {
32             name,
33             id: hir::CRATE_HIR_ID,
34             where_outer: rustc_span::DUMMY_SP,
35             where_inner: rustc_span::DUMMY_SP,
36             attrs,
37             extern_crates: Vec::new(),
38             imports: Vec::new(),
39             mods: Vec::new(),
40             items: Vec::new(),
41             traits: Vec::new(),
42             foreigns: Vec::new(),
43             macros: Vec::new(),
44             is_crate: false,
45         }
46     }
47 }
48
49 #[derive(Debug, Clone, Copy)]
50 crate enum StructType {
51     /// A braced struct
52     Plain,
53     /// A tuple struct
54     Tuple,
55     /// A unit struct
56     Unit,
57 }
58
59 crate struct Variant<'hir> {
60     crate name: Symbol,
61     crate id: hir::HirId,
62     crate def: &'hir hir::VariantData<'hir>,
63 }
64
65 crate struct Trait<'hir> {
66     crate is_auto: hir::IsAuto,
67     crate unsafety: hir::Unsafety,
68     crate name: Symbol,
69     crate items: Vec<&'hir hir::TraitItem<'hir>>,
70     crate generics: &'hir hir::Generics<'hir>,
71     crate bounds: &'hir [hir::GenericBound<'hir>],
72     crate attrs: &'hir [ast::Attribute],
73     crate id: hir::HirId,
74 }
75
76 // For Macro we store the DefId instead of the NodeId, since we also create
77 // these imported macro_rules (which only have a DUMMY_NODE_ID).
78 crate struct Macro {
79     crate name: Symbol,
80     crate def_id: hir::def_id::DefId,
81     crate matchers: Vec<Span>,
82     crate imported_from: Option<Symbol>,
83 }
84
85 crate struct ExternCrate<'hir> {
86     crate name: Symbol,
87     crate hir_id: HirId,
88     crate cnum: CrateNum,
89     crate path: Option<String>,
90     crate vis: &'hir hir::Visibility<'hir>,
91     crate attrs: &'hir [ast::Attribute],
92     crate span: Span,
93 }
94
95 #[derive(Debug)]
96 crate struct Import<'hir> {
97     crate name: Symbol,
98     crate id: hir::HirId,
99     crate vis: &'hir hir::Visibility<'hir>,
100     crate attrs: &'hir [ast::Attribute],
101     crate path: &'hir hir::Path<'hir>,
102     crate glob: bool,
103     crate span: Span,
104 }
105
106 crate fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {
107     match *vdata {
108         hir::VariantData::Struct(..) => Plain,
109         hir::VariantData::Tuple(..) => Tuple,
110         hir::VariantData::Unit(..) => Unit,
111     }
112 }