Repository navigation
fix: resolve local self-crate aliases to the target root - #99
Draft
grzegorznowak wants to merge 5 commits into
Draft
grzegorznowak wants to merge 5 commits into
grzegorznowak wants to merge 5 commits into
Conversation
Admit only exact extern crate self bindings as internal aliases and distinguish their crate-root meaning from ordinary self:: paths. Add eight bounded regressions without extending inherited or chained alias resolution. Keep regressions in a focused test-only module for a small resolver diff. This fork-only inspection PR has no tracking issue; no upstream publication or merge is requested.
Add a compilable nested-alias fixture and public extraction assertions for the declaration, each qualified root reference, module suffix, diagnostics, and graph edges. Include competing lib/bin root and alias-isolation coverage. Validate the integration test against the unpatched resolver and an alias-disabled variant that retains declaration-root resolution, ensuring a declaration edge cannot hide missing qualified references.
Move the self-crate alias unit regressions into the inline extraction test module and the source-backed regression into the existing graph extraction suite, so the fix reuses established repository test mechanisms. Fold the alias-resolution and binding-precedence cases into the existing tables, drop the nested-only and ordinary-`self::` duplicates now covered through real source, and drop a vacuous line assertion plus a diagnostics check that `extract_graph` copies by construction. Coverage is unchanged: declaration and alias root resolution, competing lib/bin roots with alias isolation, module-suffix resolution, import via a renamed alias, root-module shadowing, non-self extern exclusion, and sibling isolation. The graph regression fails when alias collection is disabled while declaration-root resolution stays. Gates: cargo fmt --all -- --check, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings, cargo test --workspace --all-features (326 unit, 148 integration, 55 doctests).
Introduce `use_alias` in the extraction test module so `use`-style references with a bound name are constructed in one expression instead of starting from a plain reference and mutating kind/binding afterward. Three call sites in the alias-resolution, binding-precedence, and renamed alias tests switch to the helper. No production code or other test helpers change. Gates: cargo fmt --all -- --check, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings, cargo test --workspace --all-features (326 unit, 148 integration, 55 doctests).
Reorder the extraction test helpers so the two specialised reference builders sit together. No behavior change. Gates: cargo fmt --all -- --check, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings, cargo test --workspace --all-features (326 unit, 148 integration, 55 doctests).
grzegorznowak
marked this pull request as draft
November 15, 2026 16:05
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #98.
Architectural approach
This change stays within Extract in the existing
SOURCE → EXTRACT → PROJECT → ASSERT → REPORTpipeline. It corrects the dependency information supplied to downstream stages rather than adding alias-specific behavior to projections or architecture rules.No public API, dependency, lockfile, assertion, or reporting-policy changes are introduced.
Implementation
Two changes in
src/common/extraction/extract_dependencies.rswork together:Collect self-crate bindings as internal aliases.
collect_internal_aliasesnow acceptsImportKind::ExternCrateonly when its path is exactly["self"]. Other external-crate declarations remain excluded from internal alias collection.Resolve the declaration in the target’s root context.
resolve_directdistinguishes anExternCratedeclaration namingselffrom an ordinaryself::path. The declaration uses the existinglongest_prefixlookup with an empty module path; ordinaryself::paths remain module-relative.The lookup retains the current package, dependency scope, and Cargo target identity. A binary target therefore resolves to its own root rather than a library root in the same package.
Once collected, the binding uses the existing alias-classification and suffix-resolution paths. No second resolver, filesystem-path special case, or diagnostic suppression is added. Alias lookup remains module-local; this does not introduce inherited or chained-alias resolution.
Regression coverage