]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/doctree.rs
Merge commit '5988bbd24aa87732bfa1d111ba00bcdaa22c481a' into sync_cg_clif-2020-11-27
[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
10 crate struct Module<'hir> {
11     crate name: Option<Symbol>,
12     crate attrs: &'hir [ast::Attribute],
13     crate where_outer: Span,
14     crate where_inner: Span,
15     crate imports: Vec<Import<'hir>>,
16     crate mods: Vec<Module<'hir>>,
17     crate id: hir::HirId,
18     // (item, renamed)
19     crate items: Vec<(&'hir hir::Item<'hir>, Option<Ident>)>,
20     crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Ident>)>,
21     crate macros: Vec<Macro>,
22     crate is_crate: bool,
23 }
24
25 impl Module<'hir> {
26     crate fn new(name: Option<Symbol>, attrs: &'hir [ast::Attribute]) -> Module<'hir> {
27         Module {
28             name,
29             id: hir::CRATE_HIR_ID,
30             where_outer: rustc_span::DUMMY_SP,
31             where_inner: rustc_span::DUMMY_SP,
32             attrs,
33             imports: Vec::new(),
34             mods: Vec::new(),
35             items: Vec::new(),
36             foreigns: Vec::new(),
37             macros: Vec::new(),
38             is_crate: false,
39         }
40     }
41 }
42
43 #[derive(Debug, Clone, Copy)]
44 crate enum StructType {
45     /// A braced struct
46     Plain,
47     /// A tuple struct
48     Tuple,
49     /// A unit struct
50     Unit,
51 }
52
53 crate struct Variant<'hir> {
54     crate name: Symbol,
55     crate id: hir::HirId,
56     crate def: &'hir hir::VariantData<'hir>,
57 }
58
59 // For Macro we store the DefId instead of the NodeId, since we also create
60 // these imported macro_rules (which only have a DUMMY_NODE_ID).
61 crate struct Macro {
62     crate name: Symbol,
63     crate def_id: hir::def_id::DefId,
64     crate matchers: Vec<Span>,
65     crate imported_from: Option<Symbol>,
66 }
67
68 #[derive(Debug)]
69 crate struct Import<'hir> {
70     crate name: Symbol,
71     crate id: hir::HirId,
72     crate vis: &'hir hir::Visibility<'hir>,
73     crate attrs: &'hir [ast::Attribute],
74     crate path: &'hir hir::Path<'hir>,
75     crate glob: bool,
76     crate span: Span,
77 }
78
79 crate fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {
80     match *vdata {
81         hir::VariantData::Struct(..) => Plain,
82         hir::VariantData::Tuple(..) => Tuple,
83         hir::VariantData::Unit(..) => Unit,
84     }
85 }