Skip to content

fix: bind each cfg/impl twin module's functions through their own use (#1017) - #1163

Merged
vitali87 merged 1 commit into
mainfrom
fix/1017-two-impls-mod-inner
Aug 10, 2026
Merged

fix: bind each cfg/impl twin module's functions through their own use (#1017)#1163
vitali87 merged 1 commit into
mainfrom
fix/1017-two-impls-mod-inner

Conversation

@vitali87

@vitali87 vitali87 commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Closes the remaining observable mis-binding in #1017.

Context

Most of #1017 is already handled on main via span-gating + cross-file arbitration (not module-qn dedup, which would break super::/self::/crate:: path resolution). The common colliding shapes have passing tests. This closes the one shape that still mis-bound and had no test.

The bug

When two bodied modules share one qn — two mutually-exclusive cfg twins, or two impls of one type each with a method-local mod inner — both are indexed and their mod-scope use maps merge onto the shared import_mapping[qn] (last writer wins). A function in the earlier twin then binds through the later twin's imports:

#[cfg(feature = "ext")]      pub mod run { use crate::alpha::helper; pub fn ga() -> u32 { helper() } }
#[cfg(not(feature = "ext"))] pub mod run { use crate::beta::helper;  pub fn gb() -> u32 { helper() } }

ga wrongly resolved to beta::helper instead of alpha::helper.

Fix

_parse_rust_use_declaration already fans an inline-mod use out to its own functions' spans as weak fn-scope entries — but only for non-pure chains (fn-local mods). Pure twins skipped it, so they merged on the shared key. Dropping the if not pure_chain: guard makes every inline-mod use also register span-gated per its own functions, so each function binds through its enclosing mod body regardless of what the merged key holds.

enclosing_mod_fn_spans returns spans only for a use sitting directly in an inline mod {} body, so file-level and mod foo; uses are untouched — the change is confined to inline bodied mods, exactly where twins occur.

Tests (both RED-verified)

  • test_two_bodied_cfg_twin_mods_keep_separate_uses — the cfg-twin case above; each twin's fn binds its own helper. Reverting the fix flips ga to beta.
  • test_two_impls_method_local_mod_inner_keep_separate_uses — two impls of S, each a method-local mod inner importing a different helper.
  • Full test_rust_crate_path_trait_linking.py: 139 passed, 2 skipped, no regressions. Block-item suites: 11 passed. Lint + type-check clean.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Rust import resolution inside inline modules.
    • Prevented imports from separate implementation blocks or configuration-specific module variants from being incorrectly shared.
    • Preserved distinct helper imports for isolated modules, improving code navigation and analysis accuracy.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 55d319cd-96d2-4ad3-b3db-0cf24daa9501

📥 Commits

Reviewing files that changed from the base of the PR and between c4c543b and 5405654.

📒 Files selected for processing (2)
  • codebase_rag/parsers/import_processor.py
  • codebase_rag/tests/test_rust_crate_path_trait_linking.py

📝 Walkthrough

Walkthrough

Rust inline-module imports now fan out into enclosing function scopes for both pure and non-pure chains. Regression tests verify that duplicate impl-local and cfg-gated modules keep separate helper imports.

Changes

Rust inline-module import resolution

Layer / File(s) Summary
Function-scope import fan-out and regression coverage
codebase_rag/parsers/import_processor.py, codebase_rag/tests/test_rust_crate_path_trait_linking.py
Inline-module imports now create weak function-scope entries for all module chains. Regression tests verify separate mappings for duplicate impl-local modules and cfg-gated module twins. File-level uses remain unchanged.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the fix for separate function binding in cfg and impl twin modules and follows Conventional Commits format.
Description check ✅ Passed The description clearly covers the bug, fix, affected scope, related issue, regression tests, and validation results, despite not following every template heading.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1017-two-impls-mod-inner

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This change keeps Rust call resolution scoped to each inline module body when multiple bodies share the same qualified name. A before-and-after check reproduced the former cfg-gated module cross-binding, then confirmed that cfg-gated twins and method-local modules each resolve their helper call through their own use declaration. The complete Rust crate-path trait-linking test suite passed with 141 tests.

Confidence Score: 5/5

The change is safe to merge based on isolated end-to-end call-resolution checks and the passing focused Rust linking suite.

The tested duplicate-module scenarios now preserve lexical import isolation, and no remaining correctness defects were found.

Files Needing Attention: No files need further attention; codebase_rag/parsers/import_processor.py and its Rust regression coverage were exercised.

T-Rex T-Rex Logs

What T-Rex did

  • Ran an authored parent-versus-head harness that generates cfg-twin and method-local-twin Rust modules with distinct helper imports.
  • On the parent commit, foo.run.ga resolved to beta.helper instead of alpha.helper, and after the change, the isolation cases passed.
  • Ran uv run pytest codebase_rag/tests/test_rust_crate_path_trait_linking.py -q, which completed with 141 passing tests, validating separate inline module bindings.
  • Before: cfg twin resolution was contaminated by the sibling body; After: both isolated lexical-binding tests passed (2 passed), proving the regression fix at the intended scope.
  • Authored source and command-captured before/after outputs were uploaded to support the validation done in this PR.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (1): Last reviewed commit: "fix: bind each cfg/impl twin module's fu..." | Re-trigger Greptile

@sonarqubecloud

Copy link
Copy Markdown

@vitali87
vitali87 merged commit 554a5e9 into main Aug 10, 2026
26 checks passed
@vitali87
vitali87 deleted the fix/1017-two-impls-mod-inner branch August 10, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant