Skip to content

Add new path_attribute lint - #17798

Closed
GauravPawar101 wants to merge 1 commit into
rust-lang:masterfrom
GauravPawar101:add-path-attribute-lint
Closed

GauravPawar101 wants to merge 1 commit into
rust-lang:masterfrom
GauravPawar101:add-path-attribute-lint

Conversation

@GauravPawar101

@GauravPawar101 GauravPawar101 commented Sep 27, 2026 •

Copy link
Copy Markdown

Detects use of the built-in #[path = "..."] attribute to override the source file of an out-of-line module.

With the conventional module layout, a module's source file is predictable from its name, which keeps the module tree navigable for readers and for tooling. #[path] breaks that correspondence, and rustc additionally resolves nested mod declarations in a #[path]-included file relative to that file's directory rather than to a directory named after the module, so the relationship is not just unconventional but easy to get wrong.

#[path] remains the only way to express a non-standard module layout and is legitimately needed for generated code, platform-specific implementations and tests, so the lint is in the restriction group and allow-by-default.

Unlike self_named_module_files, mod_module_files and inline_modules, none of which prohibit overriding a module's source path, this lint specifically targets the attribute itself.

The lint does not fire for #[path] on an inline module, which only changes the directory that nested mod declarations resolve against.

Replaces the closed #17788, whose branch also carried the useless_attribute fixes. This branch now contains only the new lint.

Detects use of the built-in `#[path = "..."]` attribute to override the
source file of an out-of-line module.

With the conventional module layout, a module's source file is predictable
from its name, which keeps the module tree navigable for readers and for
tooling. `#[path]` breaks that correspondence, and rustc additionally
resolves nested `mod` declarations in a `#[path]`-included file relative to
that file's directory rather than to a directory named after the module, so
the relationship is not just unconventional but easy to get wrong.

`#[path]` remains the only way to express a non-standard module layout and is
legitimately needed for generated code, platform-specific implementations and
tests, so the lint is in the `restriction` group and allow-by-default.

Unlike `self_named_module_files`, `mod_module_files` and `inline_modules`,
none of which prohibit overriding a module's source path, this lint
specifically targets the attribute itself.

The lint does not fire for `#[path]` on an inline module, which only changes
the directory that nested `mod` declarations resolve against.
@rustbot rustbot added the S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. label Sep 27, 2026
@rustbot

rustbot commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome!

You should hear from one of our reviewers after this PR gets at least 2 reviews from the community.

Please see the contribution instructions for more information.

@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Sep 27, 2026
@rustbot rustbot removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. labels Sep 27, 2026
@github-actions

Copy link
Copy Markdown

Lintcheck changes for f4c011d

Lint Added Removed Changed
clippy::path_attribute 36 0 0

This comment will be updated if you push new changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp PRs that add, remove, or rename lints and need an FCP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants