]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/doctree.rs
Auto merge of #80623 - flip1995:clippyup, r=Manishearth
[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, Span, Symbol};
7
8 use rustc_hir as hir;
9
10 crate struct Module<'hir> {
11     crate name: Option<Symbol>,
12     crate where_outer: Span,
13     crate where_inner: Span,
14     crate imports: Vec<Import<'hir>>,
15     crate mods: Vec<Module<'hir>>,
16     crate id: hir::HirId,
17     // (item, renamed)
18     crate items: Vec<(&'hir hir::Item<'hir>, Option<Symbol>)>,
19     crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Symbol>)>,
20     crate macros: Vec<(&'hir hir::MacroDef<'hir>, Option<Symbol>)>,
21     crate is_crate: bool,
22 }
23
24 impl Module<'hir> {
25     crate fn new(name: Option<Symbol>) -> Module<'hir> {
26         Module {
27             name,
28             id: hir::CRATE_HIR_ID,
29             where_outer: rustc_span::DUMMY_SP,
30             where_inner: rustc_span::DUMMY_SP,
31             imports: Vec::new(),
32             mods: Vec::new(),
33             items: Vec::new(),
34             foreigns: Vec::new(),
35             macros: Vec::new(),
36             is_crate: false,
37         }
38     }
39 }
40
41 #[derive(Debug, Clone, Copy)]
42 crate enum StructType {
43     /// A braced struct
44     Plain,
45     /// A tuple struct
46     Tuple,
47     /// A unit struct
48     Unit,
49 }
50
51 crate struct Variant<'hir> {
52     crate name: Symbol,
53     crate id: hir::HirId,
54     crate def: &'hir hir::VariantData<'hir>,
55 }
56
57 #[derive(Debug)]
58 crate struct Import<'hir> {
59     crate name: Symbol,
60     crate id: hir::HirId,
61     crate vis: &'hir hir::Visibility<'hir>,
62     crate attrs: &'hir [ast::Attribute],
63     crate path: &'hir hir::Path<'hir>,
64     crate glob: bool,
65     crate span: Span,
66 }
67
68 crate fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {
69     match *vdata {
70         hir::VariantData::Struct(..) => Plain,
71         hir::VariantData::Tuple(..) => Tuple,
72         hir::VariantData::Unit(..) => Unit,
73     }
74 }