Skip to main content

pedant_core/ir/sites/
declaration.rs

1//! One `mod` item and the source or inline body it selects.
2
3use crate::ir::cfg::RustCfgCondition;
4
5/// A `mod` item, whether it holds an inline body or names another source.
6///
7/// The module closure reads this table rather than walking the syntax tree a
8/// second time, so `#[path]`, inline bodies, and conditional compilation have
9/// one owner.
10#[derive(Debug)]
11pub struct ModuleDeclarationSite {
12    /// The declared module name.
13    pub name: Box<str>,
14    /// Every `#[path = "…"]` override the item carries, in attribute order.
15    ///
16    /// Usually empty or one entry. Several appear when mutually exclusive
17    /// `cfg_attr` predicates give one module a source per configuration, which
18    /// is how a crate selects between a platform's or feature's
19    /// implementations. Conditions are recorded, never evaluated, so every
20    /// alternative stays visible.
21    pub declared_paths: Box<[Box<str>]>,
22    /// Index into `FileIr::definition_sites` of the module this item defines.
23    pub definition: usize,
24    /// The scope this item opens, for an inline module only.
25    pub inline_scope: Option<usize>,
26    /// The scope this item is declared in.
27    pub scope: usize,
28    pub(crate) condition: RustCfgCondition,
29}
30
31impl ModuleDeclarationSite {
32    /// The condition guarding this declaration, and through it the whole
33    /// module instance the declaration selects.
34    pub(crate) fn condition(&self) -> &RustCfgCondition {
35        &self.condition
36    }
37}