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 foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Ident>)>,
24 crate macros: Vec<Macro>,
29 crate fn new(name: Option<Symbol>, attrs: &'hir [ast::Attribute]) -> Module<'hir> {
32 id: hir::CRATE_HIR_ID,
33 where_outer: rustc_span::DUMMY_SP,
34 where_inner: rustc_span::DUMMY_SP,
36 extern_crates: Vec::new(),
47 #[derive(Debug, Clone, Copy)]
48 crate enum StructType {
57 crate struct Variant<'hir> {
60 crate def: &'hir hir::VariantData<'hir>,
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).
67 crate def_id: hir::def_id::DefId,
68 crate matchers: Vec<Span>,
69 crate imported_from: Option<Symbol>,
72 crate struct ExternCrate<'hir> {
76 crate path: Option<String>,
77 crate vis: &'hir hir::Visibility<'hir>,
78 crate attrs: &'hir [ast::Attribute],
83 crate struct Import<'hir> {
86 crate vis: &'hir hir::Visibility<'hir>,
87 crate attrs: &'hir [ast::Attribute],
88 crate path: &'hir hir::Path<'hir>,
93 crate fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {
95 hir::VariantData::Struct(..) => Plain,
96 hir::VariantData::Tuple(..) => Tuple,
97 hir::VariantData::Unit(..) => Unit,