Skip to main content

ImportScope

Struct ImportScope 

Source
pub struct ImportScope {
    pub file_module: Option<String>,
    pub qualified_modules: BTreeSet<String>,
    pub bare_imports: BTreeSet<(String, String)>,
    pub aliases: BTreeMap<String, (String, String)>,
}
Expand description

Per-file import context threaded into resolution (M-2d, docs/modules-spec.md §2; issue #790) so a bare reference with multiple cross-module candidates binds to the module this file actually imports — “names cross module boundaries only via import” — rather than to the flat duplicate-winner.

The default (empty) scope reproduces the pre-M-2d flat behavior exactly: the entire strict-ink and single-module world has at most one candidate per (name, kind), so [lookup_by_name]’s fast path returns it unchanged and this context never influences the result. It only ever disambiguates the genuinely-new case unlocked by relaxing the #784/#793 stopgap: two declared modules publicly defining the same name, now coexisting in the index instead of one being suppressed.

Fields§

§file_module: Option<String>

The referring file’s own declared module (None for an undeclared stem-module / the legacy world). A candidate declared in this same module is bare-visible without any import.

§qualified_modules: BTreeSet<String>

Modules this file imports qualified (IMPORT mod) — licenses module.name access to any public export of that module.

§bare_imports: BTreeSet<(String, String)>

(module, name) pairs this file imports bare (IMPORT { name } FROM mod) — name-precise, matching modules::import_covers exactly so resolution and the E025 import-required diagnostic can never diverge. BTreeSet for determinism. Keyed by the imported item’s own (source-module) name regardless of any local alias — an aliased import still covers its source name for cross-module licensing purposes (§2: the file did import it), it just isn’t the name resolution binds bare (see aliases).

§aliases: BTreeMap<String, (String, String)>

Local alias → (module, source_name) for every bare import item that named one (IMPORT { name AS alias } FROM mod / use mod::name as alias;, issue #1590). index.by_name is keyed by definitions’ own spellings only, so a plain [lookup_by_name] lookup can never find an alias — this table is the indirection [lookup_by_name] falls back to once the direct-name lookup comes up empty. Additive, not shadowing: aliasing doesn’t revoke the source name’s own bare visibility (still governed by bare_imports/classify exactly as before) — it only adds a second local spelling for the same import. See the doc comment on [lookup_by_name] for the alias-vs-original licensing ruling. BTreeMap for determinism.

Implementations§

Source§

impl ImportScope

Source

pub fn new(file_module: Option<String>, imports: &[Import]) -> Self

Build the scope for one file from its resolved (declared) module and its HIR IMPORT list.

Trait Implementations§

Source§

impl Clone for ImportScope

Source§

fn clone(&self) -> ImportScope

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ImportScope

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ImportScope

Source§

fn default() -> ImportScope

Returns the “default value” for a type. Read more
Source§

impl Eq for ImportScope

Source§

impl PartialEq for ImportScope

Source§

fn eq(&self, other: &ImportScope) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ImportScope

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more