rustc_middle/
metadata.rs

1use rustc_hir::def::Res;
2use rustc_macros::{HashStable, TyDecodable, TyEncodable};
3use rustc_span::Ident;
4use rustc_span::def_id::DefId;
5use smallvec::SmallVec;
6
7use crate::ty;
8
9/// A simplified version of `ImportKind` from resolve.
10/// `DefId`s here correspond to `use` and `extern crate` items themselves, not their targets.
11#[derive(Clone, Copy, Debug, TyEncodable, TyDecodable, HashStable)]
12pub enum Reexport {
13    Single(DefId),
14    Glob(DefId),
15    ExternCrate(DefId),
16    MacroUse,
17    MacroExport,
18}
19
20impl Reexport {
21    pub fn id(self) -> Option<DefId> {
22        match self {
23            Reexport::Single(id) | Reexport::Glob(id) | Reexport::ExternCrate(id) => Some(id),
24            Reexport::MacroUse | Reexport::MacroExport => None,
25        }
26    }
27}
28
29/// This structure is supposed to keep enough data to re-create `NameBinding`s for other crates
30/// during name resolution. Right now the bindings are not recreated entirely precisely so we may
31/// need to add more data in the future to correctly support macros 2.0, for example.
32/// Module child can be either a proper item or a reexport (including private imports).
33/// In case of reexport all the fields describe the reexport item itself, not what it refers to.
34#[derive(Debug, TyEncodable, TyDecodable, HashStable)]
35pub struct ModChild {
36    /// Name of the item.
37    pub ident: Ident,
38    /// Resolution result corresponding to the item.
39    /// Local variables cannot be exported, so this `Res` doesn't need the ID parameter.
40    pub res: Res<!>,
41    /// Visibility of the item.
42    pub vis: ty::Visibility<DefId>,
43    /// Reexport chain linking this module child to its original reexported item.
44    /// Empty if the module child is a proper item.
45    pub reexport_chain: SmallVec<[Reexport; 2]>,
46}