Skip to content

feat(rust): accept literal #[path] modules inside their own crate - #234

Closed
FredApps wants to merge 4 commits into
DiffCI:mainfrom
FredApps:rust/path-attributes
Closed

FredApps wants to merge 4 commits into
DiffCI:mainfrom
FredApps:rust/path-attributes

Conversation

@FredApps

@FredApps FredApps commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #226

Literal #[path] modules that stay inside their own crate no longer make the repository fall back. That includes the common platform pattern:

#[cfg_attr(unix, path = "sys/unix.rs")]
#[cfg_attr(windows, path = "sys/windows.rs")]
mod sys;

How it resolves (Rust reference rules, checked against rustc):

  • relative to the file's directory;
  • inside inline mod a { … } blocks, also relative to those module names (for crate roots and mod.rs).

Every target must be a tracked .rs file, realpath'd inside the repository and owned by the same package. It's already a source of that crate, so crate-granular selection stays correct, and it also gets an import edge from the declaring file. Each target's directory is added to the inventory check, because modules it declares are looked up from there.

Still falls back:

  • paths outside the crate, or missing files;
  • #[path] on an inline module;
  • #![path];
  • a non-literal value;
  • path anywhere other than directly in the attribute or as a cfg_attr item;
  • #[path] inside an inline module of a file that isn't a crate root or mod.rs, because there the base depends on how that file was itself loaded.

The new test covers the accepted forms, the inventory check for an out-of-tree target, and each fallback.

Validation (Linux, Node 22, Cargo 1.100): npm run typecheck and the Rust test files (tests/repo/rust-*.test.ts, tests/planner/rust-command.test.ts) pass. The new test fails on main and passes here.

Merge order (#131 series: #232, #234, #248, #250, #252, #254, #256, #277, #258). These all edit the one-line Rust paragraph in docs/using-diffci.md, and some also touch rust.ts/types.ts, so they conflict textually with each other. #258 already includes #232, #248, #250 and #254 with those conflicts resolved. The simplest path: merge #258 (GitHub marks those four as merged), then #234, #252, #256 and #277. After each one lands I merge main into the next and resolve the docs line. Merging them one at a time in number order works too, with the same main merge after each.

@FredApps
FredApps marked this pull request as ready for review November 17, 2026 17:18
@FredApps
FredApps marked this pull request as draft November 17, 2026 17:19
@FredApps
FredApps marked this pull request as ready for review November 17, 2026 17:41
I, FredApps <[email protected]>, hereby add my Signed-off-by to this commit: 3945dba
I, FredApps <[email protected]>, hereby add my Signed-off-by to this commit: c9e8e5a
I, FredApps <[email protected]>, hereby add my Signed-off-by to this commit: ae37fab

Signed-off-by: FredApps <[email protected]>
@adityankale190895

Copy link
Copy Markdown
Member

#258 is merged (it brought in #232, #248, #250 and #254), along with #228-#231 and #233, so this branch now conflicts with main in src/repo/adapters/rust.ts, as you expected in #258.

Could you merge main into it? Once it's green I'll check it alongside the other Rust PRs and merge it. Thanks for keeping the Rust series moving.

adityankale190895 pushed a commit that referenced this pull request Nov 18, 2026
A literal #[path = "..."] on a module declaration is resolved relative to
the declaring file (inline module names apply only in crate roots and
mod.rs) and accepted when the target is a tracked .rs file in the same
package; anything else still falls back. Fixes #226.

Signed-off-by: FredApps <[email protected]>
@adityankale190895

Copy link
Copy Markdown
Member

Merged to main as 167c2a8 (squashed, authorship kept). It conflicted with main only on the rustInputs return type, so I kept both module? and runsPrograms there. Thanks!

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.

Rust adapter: accept literal #[path] modules inside their own crate

2 participants