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::*;
6 use rustc_span::hygiene::MacroKind;
7 use rustc_span::{self, symbol::Ident, Span, Symbol};
10 use rustc_hir::def_id::CrateNum;
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>>,
24 crate items: Vec<(&'hir hir::Item<'hir>, Option<Ident>)>,
25 crate traits: Vec<Trait<'hir>>,
26 crate impls: Vec<Impl<'hir>>,
27 crate foreigns: Vec<ForeignItem<'hir>>,
28 crate macros: Vec<Macro>,
29 crate proc_macros: Vec<ProcMacro>,
34 crate fn new(name: Option<Symbol>, attrs: &'hir [ast::Attribute]) -> Module<'hir> {
37 id: hir::CRATE_HIR_ID,
38 where_outer: rustc_span::DUMMY_SP,
39 where_inner: rustc_span::DUMMY_SP,
41 extern_crates: Vec::new(),
50 proc_macros: Vec::new(),
56 #[derive(Debug, Clone, Copy)]
57 crate enum StructType {
66 crate struct Variant<'hir> {
69 crate def: &'hir hir::VariantData<'hir>,
72 crate struct Function<'hir> {
73 crate decl: &'hir hir::FnDecl<'hir>,
76 crate header: hir::FnHeader,
77 crate generics: &'hir hir::Generics<'hir>,
78 crate body: hir::BodyId,
81 crate struct Trait<'hir> {
82 crate is_auto: hir::IsAuto,
83 crate unsafety: hir::Unsafety,
85 crate items: Vec<&'hir hir::TraitItem<'hir>>,
86 crate generics: &'hir hir::Generics<'hir>,
87 crate bounds: &'hir [hir::GenericBound<'hir>],
88 crate attrs: &'hir [ast::Attribute],
93 crate struct Impl<'hir> {
94 crate unsafety: hir::Unsafety,
95 crate polarity: hir::ImplPolarity,
96 crate defaultness: hir::Defaultness,
97 crate constness: hir::Constness,
98 crate generics: &'hir hir::Generics<'hir>,
99 crate trait_: &'hir Option<hir::TraitRef<'hir>>,
100 crate for_: &'hir hir::Ty<'hir>,
101 crate items: Vec<&'hir hir::ImplItem<'hir>>,
102 crate attrs: &'hir [ast::Attribute],
104 crate vis: &'hir hir::Visibility<'hir>,
105 crate id: hir::HirId,
108 crate struct ForeignItem<'hir> {
109 crate id: hir::HirId,
111 crate kind: &'hir hir::ForeignItemKind<'hir>,
114 // For Macro we store the DefId instead of the NodeId, since we also create
115 // these imported macro_rules (which only have a DUMMY_NODE_ID).
118 crate def_id: hir::def_id::DefId,
119 crate matchers: Vec<Span>,
120 crate imported_from: Option<Symbol>,
123 crate struct ExternCrate<'hir> {
126 crate cnum: CrateNum,
127 crate path: Option<String>,
128 crate vis: &'hir hir::Visibility<'hir>,
129 crate attrs: &'hir [ast::Attribute],
134 crate struct Import<'hir> {
136 crate id: hir::HirId,
137 crate vis: &'hir hir::Visibility<'hir>,
138 crate attrs: &'hir [ast::Attribute],
139 crate path: &'hir hir::Path<'hir>,
144 crate struct ProcMacro {
146 crate id: hir::HirId,
147 crate kind: MacroKind,
148 crate helpers: Vec<Symbol>,
151 crate fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {
153 hir::VariantData::Struct(..) => Plain,
154 hir::VariantData::Tuple(..) => Tuple,
155 hir::VariantData::Unit(..) => Unit,