crates.sage_ir.resolution.lookup.expansion_import_ambiguity

Expansion cannot silently change an unqualified import root. Final import validation rejects a relative import whose first segment has a macro-generated direct or named-import binding and a glob binding to a distinct definition in the same namespace. This applies to unused imports and to roots of longer import paths. Glob targets and intermediate path segments use the type namespace; conflicts confined to another namespace do not make those roots ambiguous. Repeated routes to one definition are not ambiguous. Source-written named bindings retain precedence; explicitly anchored paths bypass this unqualified-root check. Validation reports the conflict after expansion without replacing the combined named-and-glob lookup used during expansion.

Read in specification context · design/crates/sage_ir/resolution.sage

Implementation

Implemented crates/sage-ir/src/check/resolve/mod.rs:175–180

sage_ir::check::resolve · lib:sage_ir

#![allow(unused)]
fn main() {
    // {anchor}`crates.sage_ir.resolution.lookup.expansion_import_ambiguity`
    pub fn import_root_is_expansion_ambiguous(
        &mut self,
        stash: &Stash,
        path: Path<'db>,
        namespace: Namespace,

}

See more source ↗

Implemented crates/sage-ir/src/local_syms/mods.rs:336–341

sage_ir::local_syms::mods · lib:sage_ir

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_ir.resolution.lookup.expansion_import_ambiguity`
pub(crate) fn symbol_local_item<'db>(
    db: &'db dyn Db,
    symbol: Symbol<'db>,
) -> Option<LocalModItemSym<'db>> {
    match symbol.data(db) {

}

See more source ↗

Implemented crates/sage-ir/src/local_syms/uses.rs:44–49

sage_ir::local_syms::uses · lib:sage_ir

#![allow(unused)]
fn main() {
    // {anchor}`crates.sage_ir.resolution.lookup.expansion_import_ambiguity`
    // {anchor}`crates.sage_ir.resolution.lookup.precedence`
    pub fn diagnostics(self, db: &'db dyn crate::Db) -> Vec<crate::diagnostic::Diagnostic<'db>> {
        use crate::cst::uses::UseKind;
        use crate::diagnostic::{Diagnostic, Span};
        use crate::resolve::{MacroKind, Namespace, Resolver};

}

See more source ↗

Tests and review

Indexed tests and the implementation-completeness and test-adequacy review; no test run is implied.

Implemented sage_test_harness::ambiguous_root_of_longer_import_is_rejected

crates/sage-test-harness/tests/macro_glob_paths.rs · test:macro_glob_paths

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_ir.resolution.lookup.expansion_import_ambiguity)]
fn ambiguous_root_of_longer_import_is_rejected() {
    compile_test! {
        source: indoc! {r#"
            mod first { pub struct Item { pub value: u16 } }
            mod second { pub struct Item { pub value: bool } }
            mod seed { pub(crate) use crate::first as path; }
            use seed::*;
            use path::Item; //# ERROR
            macro_rules! build { () => { mod path { pub(crate) use crate::second::Item; } }; }
            build!();
        "#},
        diagnostics: expect![[r#"
            error: ambiguous import: macro-generated binding conflicts with glob import
             --> src/lib.rs:5:5
              |
            5 | use path::Item; //# ERROR
              |     ^^^^^^^^^^"#]],
    }
}
}

See more source ↗

Implemented sage_test_harness::generated_import_and_binding_in_same_expansion_conflict

crates/sage-test-harness/tests/macro_glob_paths.rs · test:macro_glob_paths

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_ir.resolution.lookup.expansion_import_ambiguity)]
fn generated_import_and_binding_in_same_expansion_conflict() {
    compile_test! {
        source: indoc! {r#"
            mod first { pub struct Item { pub value: u16 } }
            mod second { pub struct Item { pub value: bool } }
            mod seed { pub(crate) use crate::first as path; }
            use seed::*;
            macro_rules! build { () => {
                mod path { pub(crate) use crate::second::Item; }
                use path::*;
            }; }
            build!(); //# ERROR
        "#},
        diagnostics: expect![[r#"
            error: ambiguous import: macro-generated binding conflicts with glob import
             --> src/lib.rs:9:1
              |
            9 | build!(); //# ERROR
              | ^^^^^^^^"#]],
    }
}
}

See more source ↗

Implemented sage_test_harness::generated_module_competes_with_glob_import_path

crates/sage-test-harness/tests/macro_glob_paths.rs · test:macro_glob_paths

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_ir.resolution.lookup.precedence)]
#[sage::test(crates.sage_ir.resolution.lookup.expansion_import_ambiguity)]
fn generated_module_competes_with_glob_import_path() {
    // The imported contents are unused: validating the import itself must
    // reject the expansion-sensitive ambiguity in both compilers.
    compile_test! {
        source: indoc! {r#"
            mod first {
                pub struct Item { pub value: u16 }
            }
            mod second {
                pub struct Item { pub value: bool }
            }
            mod seed { pub(crate) use crate::first as path; }
            use seed::*;
            use path::*; //# ERROR
            macro_rules! build { () => { mod path { pub(crate) use crate::second::Item; } }; }
            build!();
        "#},
        diagnostics: expect![[r#"
            error: ambiguous import: macro-generated binding conflicts with glob import
             --> src/lib.rs:9:5
              |
            9 | use path::*; //# ERROR
              |     ^^^^^^^"#]],
    }
}
}

See more source ↗

Implemented sage_test_harness::generated_named_import_and_glob_can_reach_same_definition

crates/sage-test-harness/tests/macro_glob_paths.rs · test:macro_glob_paths

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_ir.resolution.lookup.expansion_import_ambiguity)]
fn generated_named_import_and_glob_can_reach_same_definition() {
    compile_test! {
        source: indoc! {r#"
            mod first { pub struct Item { pub value: u16 } }
            mod second { pub struct Item { pub value: bool } }
            mod seed { pub(crate) use crate::first as path; }
            use seed::*;
            use path::*;
            macro_rules! build { () => { use crate::first as path; }; }
            build!();
            fn example(item: Item) -> u16 { item.value }
        "#},
    }
}
}

See more source ↗

Implemented sage_test_harness::generated_named_import_competes_with_glob_root

crates/sage-test-harness/tests/macro_glob_paths.rs · test:macro_glob_paths

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_ir.resolution.lookup.expansion_import_ambiguity)]
fn generated_named_import_competes_with_glob_root() {
    compile_test! {
        source: indoc! {r#"
            mod first { pub struct Item { pub value: u16 } }
            mod second { pub struct Item { pub value: bool } }
            mod seed { pub(crate) use crate::first as path; }
            use seed::*;
            use path::*; //# ERROR
            macro_rules! build { () => { use crate::second as path; }; }
            build!();
        "#},
        diagnostics: expect![[r#"
            error: ambiguous import: macro-generated binding conflicts with glob import
             --> src/lib.rs:5:5
              |
            5 | use path::*; //# ERROR
              |     ^^^^^^^"#]],
    }
}
}

See more source ↗

Implemented sage_test_harness::glob_root_ignores_conflicting_value_namespace_bindings

crates/sage-test-harness/tests/macro_glob_paths.rs · test:macro_glob_paths

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_ir.resolution.lookup.expansion_import_ambiguity)]
fn glob_root_ignores_conflicting_value_namespace_bindings() {
    compile_test! {
        source: indoc! {r#"
            mod seed { pub fn path() {} }
            use seed::*;
            mod path { pub struct Item; }
            use path::*;
            macro_rules! build { () => { fn path() {} }; }
            build!();
            fn example(_: Item) {}
        "#},
    }
}
}

See more source ↗

Implemented sage_test_harness::nested_expansion_competes_with_glob_root

crates/sage-test-harness/tests/macro_glob_paths.rs · test:macro_glob_paths

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_ir.resolution.lookup.expansion_import_ambiguity)]
fn nested_expansion_competes_with_glob_root() {
    compile_test! {
        source: indoc! {r#"
            mod first { pub struct Item { pub value: u16 } }
            mod second { pub struct Item { pub value: bool } }
            mod seed { pub(crate) use crate::first as path; }
            use seed::*;
            use path::*; //# ERROR
            macro_rules! inner { () => { mod path { pub(crate) use crate::second::Item; } }; }
            macro_rules! outer { () => { inner!(); }; }
            outer!();
        "#},
        diagnostics: expect![[r#"
            error: ambiguous import: macro-generated binding conflicts with glob import
             --> src/lib.rs:5:5
              |
            5 | use path::*; //# ERROR
              |     ^^^^^^^"#]],
    }
}
}

See more source ↗

Implemented sage_test_harness::qualified_glob_path_selects_generated_module

crates/sage-test-harness/tests/macro_glob_paths.rs · test:macro_glob_paths

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_ir.resolution.lookup.precedence)]
#[sage::test(crates.sage_ir.resolution.lookup.expansion_import_ambiguity)]
fn qualified_glob_path_selects_generated_module() {
    compile_test! {
        source: indoc! {r#"
            mod first {
                pub struct Item { pub value: u16 }
            }
            mod second {
                pub struct Item { pub value: bool }
            }
            mod seed { pub(crate) use crate::first as path; }
            use seed::*;
            use crate::path::*;
            macro_rules! build { () => { mod path { pub(crate) use crate::second::Item; } }; }
            build!();
            fn example(item: Item) -> bool { item.value }
        "#},
    }
}
}

See more source ↗

Implemented sage_test_harness::source_written_alias_to_generated_module_keeps_precedence

crates/sage-test-harness/tests/macro_glob_paths.rs · test:macro_glob_paths

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_ir.resolution.lookup.expansion_import_ambiguity)]
fn source_written_alias_to_generated_module_keeps_precedence() {
    compile_test! {
        source: indoc! {r#"
            mod first { pub struct Item { pub value: u16 } }
            mod second { pub struct Item { pub value: bool } }
            mod seed { pub(crate) use crate::first as path; }
            use seed::*;
            use path::*;
            use crate::generated as path;
            macro_rules! build { () => { mod generated { pub(crate) use crate::second::Item; } }; }
            build!();
            fn example(item: Item) -> bool { item.value }
        "#},
    }
}
}

See more source ↗

Implemented sage_test_harness::source_written_module_takes_precedence_over_glob

crates/sage-test-harness/tests/macro_glob_paths.rs · test:macro_glob_paths

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_ir.resolution.lookup.precedence)]
#[sage::test(crates.sage_ir.resolution.lookup.expansion_import_ambiguity)]
fn source_written_module_takes_precedence_over_glob() {
    compile_test! {
        source: indoc! {r#"
            mod first {
                pub struct Item { pub value: u16 }
            }
            mod second {
                pub struct Item { pub value: bool }
            }
            mod seed { pub(crate) use crate::first as path; }
            use seed::*;
            use path::*;
            mod path { pub(crate) use crate::second::Item; }
            fn example(item: Item) -> bool { item.value }
        "#},
    }
}
}

See more source ↗

Review: Accepted · Codex /root/macro_fix_anchor.

Reviewed the complete expansion_import_ambiguity claim, all three implementation associations, and all ten ordinary annotated tests. No TODO/N/A entries apply. The claim concerns final validation of unqualified import roots, not a new macro-expansion scheduling algorithm or arbitrary hygiene semantics.

Implementation: Resolver::import_root_is_expansion_ambiguous accepts only relative paths, uses the type namespace for intermediate roots, and holds the root query in flight while resolving import edges. It separately collects generated named bindings and glob bindings, reporting a conflict only when both buckets reach distinct Symbol identities. NamedLookup::Generated uses the binding item span: source-written aliases to generated definitions are therefore correctly excluded. The associated symbol_local_item helper covers supported local named item kinds; captured LocalModItemSym::absolute_span routes each to its own span. Bang and derive parse sources count as generated. Existing macro-expansion lookup still combines named and glob candidates; normal lookup retains precedence. Definition deduplication in resolve_name_from_module prevents repeated routes from becoming multiple candidates.

LocalUseSym::diagnostics performs the audit for every flattened import before ordinary resolution, selects Type alone for glob targets and all importable namespaces for terminal named imports, and emits one relative-span error then continues. Captured compile/observe.rs shows the whole-crate consumer explicitly demands import diagnostics, including unused imports. The associated mods.rs fixed-point expanded item query exposes generated items before the normal-mode audit. The additional span and observer fragments are supporting dependencies; the three associated files contain the new validation algorithm, origin classification, and import entrypoint.

Tests: generated_module_competes_with_glob_import_path checks the original unused-import discrepancy with one shared ERROR marker and the exact Sage diagnostic snapshot. generated_named_import_competes_with_glob_root exercises a generated use binding, and ambiguous_root_of_longer_import_is_rejected verifies a multi-segment root. nested_expansion_competes_with_glob_root and generated_import_and_binding_in_same_expansion_conflict cover nested provenance and a generated import, including invocation-site diagnostic matching. generated_named_import_and_glob_can_reach_same_definition ensures duplicate routes are accepted and the resulting Item type is usable. qualified_glob_path_selects_generated_module checks explicit crate anchoring; source_written_module_takes_precedence_over_glob and source_written_alias_to_generated_module_keeps_precedence check source-origin precedence while confirming the selected field type. glob_root_ignores_conflicting_value_namespace_bindings protects against auditing an irrelevant namespace for a glob target. Positive fixtures omit diagnostic expectations, requiring no errors; negative fixtures require exactly the declared error. The captured prepare method unconditionally runs rustc and requires both compiler results before success, so the shared markers are differential acceptance/location evidence rather than Sage-only assertions.

Executed cargo test -p sage-test-harness --test macro_glob_paths with updating disabled: all 10 tests passed, zero ignored/failed. Existing compiler warnings were nonfatal. This review does not claim broader Rust macro conformance, which lies outside this narrow anchor. Source inspection and these assertions account for every qualification in the claim; no edits requested.

Browse crates anchors

139 anchors

Specification anchors and declared coverage
AnchorImplementationTests
crates (139)114 Implemented37 TODO2 N/A74 Implemented107 TODO
crates.sage_inspector (15)13 Implemented1 TODO2 N/A3 Implemented15 TODO
crates.sage_inspector.inspection (15)13 Implemented1 TODO2 N/A3 Implemented15 TODO
balanced_tracesImplementedTODO
canonical_ownershipImplementedImplementedTODO
derive_reflectionImplementedImplementedTODO
detail_free_indexImplementedTODO
deterministic_traceImplementedTODO
durable_navigationN/ATODO
generic_browserN/ATODO
owned_reflectionImplementedImplementedTODO
product_availabilityImplementedTODO
revision_and_demandImplementedTODO
semantic_phase_boundaryImplementedTODO
source_evidenceImplementedTODO
typed_serviceImplementedTODO
unknown_workImplementedTODOTODO
workspace_actorImplementedTODO
crates.sage_ir (90)67 Implemented34 TODO40 Implemented88 TODO
crates.sage_ir.checking (12)12 Implemented3 TODO5 Implemented12 TODO
crates.sage_ir.checking.body (5)5 Implemented2 TODO3 Implemented5 TODO
elaborationImplementedImplementedTODO
expected_typesImplementedTODOTODO
interface_dependenciesImplementedImplementedTODO
isolated_completionImplementedImplementedTODO
operator_callsImplementedTODOTODO
identity_mintingImplementedTODO
owned_productsImplementedImplementedTODO
crates.sage_ir.checking.signature (4)4 Implemented1 TODO1 Implemented4 TODO
body_independenceImplementedTODO
narrow_detailImplementedTODOTODO
owner_binderImplementedImplementedTODO
storageImplementedTODO
symbol_keyed_interfacesImplementedTODO
crates.sage_ir.crate (9)9 TODO9 TODO
explicit_restrictionsTODOTODO
identity_before_detailTODOTODO
incremental_evidenceTODOTODO
narrow_demandsTODOTODO
reexecution_and_invalidationTODOTODO
represented_completenessTODOTODO
restrictions_and_gapsTODOTODO
semantic_query_boundariesTODOTODO
terminal_incompletenessTODOTODO
crates.sage_ir.inference (8)8 Implemented6 Implemented8 TODO
atomic_checkingImplementedImplementedTODO
body_local_quiescenceImplementedImplementedTODO
canonical_boundaryImplementedImplementedTODO
completed_body_boundaryImplementedTODO
numeric_domainsImplementedImplementedTODO
subtyping_and_coercionImplementedImplementedTODO
terminal_obligationsImplementedTODO
transaction_isolationImplementedImplementedTODO
crates.sage_ir.metadata (4)4 Implemented1 TODO4 TODO
explicit_incompletenessImplementedTODO
keyed_reuseImplementedTODOTODO
product_boundariesImplementedTODO
provider_authorityImplementedTODO
crates.sage_ir.modules (8)7 Implemented1 TODO4 Implemented8 TODO
crates.sage_ir.modules.expand (4)4 Implemented2 Implemented4 TODO
completenessImplementedImplementedTODO
dependenciesImplementedTODO
direct_membersImplementedTODO
recursion_and_fixpointImplementedImplementedTODO
crates.sage_ir.modules.parse (4)3 Implemented1 TODO2 Implemented4 TODO
dependenciesImplementedTODO
detail_firewallImplementedImplementedTODO
recovery_completenessTODOTODO
syntax_identitiesImplementedImplementedTODO
crates.sage_ir.resolution (5)5 Implemented1 TODO3 Implemented4 TODO
crates.sage_ir.resolution.lookup (5)5 Implemented1 TODO3 Implemented4 TODO
completenessImplementedTODOImplementedTODO
dependenciesImplementedTODO
expansion_import_ambiguityImplementedImplemented
identity_onlyImplementedTODO
precedenceImplementedImplementedTODO
crates.sage_ir.solver (9)7 Implemented7 TODO5 Implemented9 TODO
alternative_isolationImplementedTODOImplementedTODO
bounded_completenessImplementedTODOTODO
candidate_completenessImplementedTODO
canonical_cyclesTODOTODO
canonical_outputsImplementedImplementedTODO
local_index_firewallTODOTODO
normalization_demandImplementedTODOImplementedTODO
schedule_independenceImplementedTODOImplementedTODO
shared_final_resultImplementedTODOImplementedTODO
crates.sage_ir.symbols (8)8 Implemented4 Implemented7 TODO
associated_identityImplementedImplemented
associated_interfacesImplementedTODO
body_interfacesImplementedImplementedTODO
definition_identityImplementedTODO
external_fact_queriesImplementedTODO
external_identityImplementedTODO
kind_wrappersImplementedImplementedTODO
local_identityImplementedImplementedTODO
crates.sage_ir.types (27)16 Implemented12 TODO13 Implemented27 TODO
crates.sage_ir.types.aliases (2)1 Implemented1 TODO1 Implemented2 TODO
identityImplementedImplementedTODO
revelationTODOTODO
crates.sage_ir.types.binder (1)1 Implemented1 TODO1 Implemented1 TODO
owner_parametersImplementedTODOImplementedTODO
crates.sage_ir.types.body (13)4 Implemented9 TODO3 Implemented13 TODO
awaitTODOTODO
closuresTODOTODO
conditional_patternsTODOTODO
coroutinesTODOTODO
diagnosed_recoveryImplementedImplementedTODO
elaboratedTODOImplementedTODO
for_iterationTODOTODO
indexingTODOTODO
macro_expansionTODOTODO
no_inferenceImplementedImplementedTODO
resolved_referencesImplementedTODO
try_residualTODOTODO
typed_provenanceImplementedTODO
crates.sage_ir.types.calls (2)1 Implemented1 TODO1 Implemented2 TODO
dispatch_familiesTODOTODO
selected_semanticsImplementedImplementedTODO
crates.sage_ir.types.lifetimes (2)2 Implemented2 Implemented2 TODO
dummyImplementedImplementedTODO
unchecked_borrowsImplementedImplementedTODO
crates.sage_ir.types.operators (2)2 Implemented1 Implemented2 TODO
lazy_control_flowImplementedTODO
trait_callsImplementedImplementedTODO
scoped_identitiesImplementedTODO
crates.sage_ir.types.spans (4)4 Implemented4 Implemented4 TODO
generated_identityImplementedImplementedTODO
item_originImplementedImplementedTODO
offset_reuseImplementedImplementedTODO
relative_compositionImplementedImplementedTODO
crates.sage_oracle_harness (4)4 Implemented2 TODO1 Implemented4 TODO
crates.sage_oracle_harness.crate (4)4 Implemented2 TODO1 Implemented4 TODO
deterministic_emissionImplementedTODO
exact_comparisonImplementedTODOImplementedTODO
fixed_projectionImplementedTODO
independent_coverageImplementedTODOTODO
crates.sage_stash (5)5 Implemented5 Implemented
crates.sage_stash.storage (5)5 Implemented5 Implemented
handle_ownershipImplementedImplemented
immutable_entriesImplementedImplemented
query_valueImplementedImplemented
rooted_equalityImplementedImplemented
typed_interningImplementedImplemented
crates.sage_test_harness (25)25 Implemented25 Implemented
crates.sage_test_harness.compile_tests (25)25 Implemented25 Implemented
annotation_validationImplementedImplemented
blessing_gateImplementedImplemented
callsite_updatesImplementedImplemented
checking_scopeImplementedImplemented
compiler_conditionsImplementedImplemented
completed_typesImplementedImplemented
coordinatesImplementedImplemented
dependenciesImplementedImplemented
diagnostic_countsImplementedImplemented
diagnostic_locationsImplementedImplemented
editionImplementedImplemented
fixturesImplementedImplemented
grouped_observationsImplementedImplemented
invocationImplementedImplemented
production_executionImplementedImplemented
project_isolationImplementedImplemented
query_captureImplementedImplemented
query_projectionImplementedImplemented
renderingImplementedImplemented
resolved_symbolsImplementedImplemented
review_visibilityImplementedImplemented
rustc_executionImplementedImplemented
rustc_lintsImplementedImplemented
starting_expressionsImplementedImplemented
target_lineImplementedImplemented