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::{self, symbol::Ident, Span, Symbol};
9 use rustc_hir::def_id::CrateNum;
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>>,
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>,
30 crate fn new(name: Option<Symbol>, attrs: &'hir [ast::Attribute]) -> Module<'hir> {
33 id: hir::CRATE_HIR_ID,
34 where_outer: rustc_span::DUMMY_SP,
35 where_inner: rustc_span::DUMMY_SP,
37 extern_crates: Vec::new(),
49 #[derive(Debug, Clone, Copy)]
50 crate enum StructType {
59 crate struct Variant<'hir> {
62 crate def: &'hir hir::VariantData<'hir>,
65 crate struct Trait<'hir> {
66 crate is_auto: hir::IsAuto,
67 crate unsafety: hir::Unsafety,
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],
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).
80 crate def_id: hir::def_id::DefId,
81 crate matchers: Vec<Span>,
82 crate imported_from: Option<Symbol>,
85 crate struct ExternCrate<'hir> {
89 crate path: Option<String>,
90 crate vis: &'hir hir::Visibility<'hir>,
91 crate attrs: &'hir [ast::Attribute],
96 crate struct Import<'hir> {
99 crate vis: &'hir hir::Visibility<'hir>,
100 crate attrs: &'hir [ast::Attribute],
101 crate path: &'hir hir::Path<'hir>,
106 crate fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {
108 hir::VariantData::Struct(..) => Plain,
109 hir::VariantData::Tuple(..) => Tuple,
110 hir::VariantData::Unit(..) => Unit,