Skip to content

fix: bare module::func() call resolution for src-less Rust crates nested in a picked folder - #25

Merged
MCR-3 merged 1 commit into
mainfrom
22-rust-bare-module-fallback
Sep 22, 2026
Merged

MCR-3 merged 1 commit into
mainfrom
22-rust-bare-module-fallback

Conversation

@MCR-3

@MCR-3 MCR-3 commented Sep 22, 2026

Copy link
Copy Markdown
Member

Closes #22.

A src/-less Rust tree is treated as one crate named "crate", with every module one level below the crate root - but when such a tree sits nested under a picked folder (a monorepo containing several flat-layout crates, say), the whole nesting prefix ends up inside every module name instead, and the bare-module-path resolver's one-level-below-crate-root guess (module::func() with no use needed) silently misses.

The fix

The use-imported branch already falls back to a crate-wide search (_find_fn_in_crate) when its own guess misses. The bare-path branch now gets an equivalent fallback (_find_submodule_in_crate), deliberately tighter: it requires base itself to be a real, unique submodule of the crate - not just any function of that name anywhere in it. A bare std-type call like Vec::new() must not get wired to an unrelated same-named top-level function elsewhere in the crate; matching on the module's own leaf name, rather than searching by the called function's name, avoids that.

A whole sibling crate nested deeper than expected (as opposed to a submodule of the current crate) stays explicitly out of scope, same as the issue's own "Cargo-workspace-aware crate detection beyond what already exists" exclusion - that branch now bails out honestly instead of attempting a fallback search that could never match.

Fixture

Added sample_rust_nested_project/: a minimal src-less two-file project (app/a.rs calling app/b.rs's function via a bare module path, no use), nested one level under app/ so picking the fixture's own root folder reproduces the bug directly through the normal CLI - no need to merge multiple projects by hand to trigger it.

Verification

  • Reproduced the exact scenario from the bug report (merging sample_project, sample_rust_project, sample_typescript_project into one request under folder prefixes): all 6 of sample_rust_project's edges present, including the two previously-dropped main::main -> processing::clean/-> processing::aggregate calls.
  • sample_rust_nested_project on its own: 0 edges before the fix, 1 edge after - confirms the fixture actually exercises the bug and the fix closes it.
  • python -m backend.analyzer before/after on the three canonical fixtures, byte-identical (not just counts): sample_project 16/17, sample_rust_project (unnested) 8/6, sample_typescript_project 21/18 - satisfies all three acceptance criteria.
  • Went through three rounds of /code-review, each catching something real before landing here: a false-positive risk in the first fallback (fixed by requiring a unique submodule match), then a copy-paste variable bug in the module-alias branch's own fallback and dead logic in the sibling-crate case (both fixed), then a clean pass.

…ted in a picked folder

A src-less Rust tree is treated as one crate named "crate", with every
module one level below the crate root - but when such a tree sits nested
under a picked folder (a monorepo containing several flat-layout crates,
say), the whole nesting prefix ends up inside every module name instead,
and the bare-module-path resolver's one-level-below-crate-root guess
(module::func() with no use needed) silently misses.

The use-imported branch just above it already falls back to a crate-wide
search when its own guess misses; the bare-path branch gets the same
fallback now, tightened to require base itself be a real, unique submodule
of the crate (not just any function of that name anywhere in it) - a bare
std type call like Vec::new() must not get wired to an unrelated same-named
top-level function elsewhere in the crate.

Added sample_rust_nested_project/ as a minimal src-less two-file regression
fixture, nested one level under app/ so picking the fixture's own root
folder reproduces the bug directly.

Closes #22
@MCR-3
MCR-3 merged commit 98c3116 into main Sep 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix bare module::func() call resolution for src-less Rust crates nested in a picked folder

1 participant