rust-lang / rust-lang/rust-clippy
New lint: `path_attribute`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Warns when the built-in #[path = "..."] attribute is used to override the source file of an out-of-line module.
Advantage
- Using Rust's conventional module file layout makes the relationship between module names and source files predictable for readers and tooling.
Drawbacks
#[path] is useful for generated code, platform-specific implementations, tests, and projects with non-standard source layouts. This lint would therefore belong to the restriction group and remain allow-by-default.
Example
#[path = "implementation.rs"]
mod parser;
Could be written as:
mod parser;
with the implementation moved to parser.rs or parser/mod.rs.
Comparison with existing lints
Unlike self_named_module_files, mod_module_files, and inline_modules, this lint specifically detects use of the built-in #[path] attribute.
None of those lints prohibit overriding a module's source path.
Additional Context
This is useful for projects that enforce a conventional module layout in CI.
For example, in AI-assisted development workflows, generated patches may introduce #[path] even when the conventional layout would work.
Natural-language or contributor guidelines can discourage the pattern, but cannot enforce it across every change path.
An allow-by-default restriction lint provides a machine-enforceable policy.
A more general alternative would be a configurable disallowed_attributes lint analogous to disallowed_methods, disallowed_types, and disallowed_macros.
If that is preferable to a dedicated path_attribute lint, it would also address this use case.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing self_named_module_files, mod_module_files, and inline_modules lints and the proposal's disallowed_attributes alternative. Determine whether the change should be a dedicated path_attribute lint or a configurable mechanism, then verify that the selected approach warns on out-of-line modules using #[path] while remaining allow-by-default.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100