Skip to content

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

Closed

Description

@FredApps

Any #[path] attribute makes a file fall back today (Rust computed includes or path attributes require full validation), so the whole repository runs everything. But platform modules written this way are common in real crates:

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

This pattern shows up in mio, socket2, getrandom, parking_lot_core and many others, in their own source and wherever they're vendored.

When the attribute is a plain literal on a file module (mod name;) and points inside the same crate, the adapter can check it the same way it checks include!. The rules are the Rust reference's: relative to the file's directory, and inside inline mod x { … } blocks also relative to their names. The target file is already a source of the crate, so crate-granular selection stays correct.

Proposal:

  • Accept #[path = "lit"] and #[cfg_attr(pred, path = "lit")] on mod name; when every target resolves (realpath'd) to a tracked .rs file owned by the same package.
  • Add each target's directory to the inventory check, because its own mod declarations are looked up from there.
  • Keep falling back for:
    • paths outside the crate or missing files;
    • #[path] on inline modules;
    • #![path];
    • non-literal paths;
    • #[path] inside an inline module of a file that isn't a crate root or mod.rs, where the base depends on how that file was itself loaded. A path-loaded file acts like mod.rs, which I checked with rustc.

Activity

  1. added a commit that references this issue on Nov 18, 2026
    167c2a8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions