Repository navigation
Description
Problem
Rust does not carry a use into a child module. ScopedModuleImportAlias::module_path_at resolves purely by line range, so a module alias imported in one module is still resolved for calls inside a nested mod that never imported it. That credits a relation against a target the code cannot reach — a fabricated cross-module reach, and a wrong actionable signal.
This is the same defect #3483 fixed on the direct function import path (ScopedImportedFunctionAlias::binding_at), still present on the module import path that #3487 owns. Both now share scan_lexical_use_statements and the same line_module_depths data, so the two paths are inconsistent: one honours the module boundary, the other does not.
Deterministic reproduction
Verified on main at dcb18a8 (Linux, rustc 1.95.0), by probing module_import_aliases / module_path_at directly:
use crate::alpha as a;
fn outer() { a::compute(); }
mod child {
fn inner() { a::compute(); } // E0433 in real Rust
}
fn tail() { a::compute(); }Actual:
outer line 2 -> alpha
inside mod child line 4 -> alpha <-- never imported the alias
tail line 6 -> alpha
Expected: line 4 unresolved; lines 2 and 6 unchanged.
The line-4 call does not compile — use crate::alpha as a; is not in scope inside mod child, which is E0433 — so any relation credited through it names a target the code cannot reach.
Target seam
crates/ripr/src/analysis/test_grip_evidence/related_tests/context.rs only:
ScopedModuleImportBinding— carry the nested-module line ranges, asScopedImportedFunctionBinding::nested_module_linesalready does.ScopedModuleImportAlias::module_path_at— skip a candidate whose nested-module ranges cover the queried line, alongside the existingend_is_partialguard.module_import_aliases— populate the ranges from the shared scan via the existingnested_module_line_rangeshelper andLexicalUseStatement::module_depth.
No new scanning machinery is needed; #3483 already added and merged all of it.
Acceptance criteria
- A module alias imported in an enclosing module is not resolved for a call inside a nested
modthat never imported it. - A nested module that imports its own module alias resolves to its own target.
- The enclosing binding resumes after the nested module closes.
- Blocks,
implbodies, andfnbodies remain unaffected — they are not module boundaries, so a function-localusestill shadows the file-level one inside its own block and stops at its closing brace. - The existing
end_is_partialmid-line scope-close guard and the same-scope ambiguity guard keep their current behaviour. - A discriminating regression fails if the exclusion is removed, and a positive control fails if the alias stops resolving where it legitimately should.
Proof
cargo test -p ripr analysis::test_grip_evidence::tests -- --nocapture
cargo test -p ripr --lib
cargo clippy -p ripr --all-targets -- -D warnings
cargo fmt --all -- --check
cargo xtask goldens check
cargo xtask dogfood
cargo xtask precommitNote on goldens: when #3483 made the equivalent change on the direct-function path, goldens check, dogfood, and fixtures all came back clean with nothing re-blessed. That is the expected result here too, because the construct being declined does not compile and so cannot appear in a corpus that builds. A moved golden would be the interesting signal — it would mean a fixture had been credited through a binding it could not actually reach.
Non-goals
- Chaining
super::/self::re-exports to their targets. Those stay fail-closed, as on the direct-function path. - Complete Rust name or call-graph resolution, cross-crate reachability, macro expansion, dynamic dispatch.
- Any change to the direct-function alias path, which fix(analysis): stop direct-import aliases crossing a module boundary (#3413) #3483 settled.
Risk and rollback
Fail-closed in direction: the change only ever withholds a binding that Rust itself would not provide, so it cannot invent a new relation. Rollback is reverting the one commit; no schema, stored state, fixture, or golden migration is involved.
Provenance
Found while reviewing the #3487 reconciliation on #3483, and raised there rather than folded in, because it widens that PR's single acceptance criterion onto a path #3487 owned and its red gate needed only a formatting fix. Filing it here so the finding is durable rather than living in a merged PR comment.
Related: #3413 (parent claim, acceptance complete), #3483, #3487.
Activity
fix(analysis): fail closed on inline nested-module opening lines (#3544…
fix(analysis): isolate module import aliases by scope (#3550)