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