New lint: definition_in_module_root - #16965
Conversation
|
rustbot has assigned @samueltardieu. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Lintcheck changes for 518f8ea
This comment will be updated if you push new changes |
fa6e565 to
810fe1d
Compare
|
Reminder, once the PR becomes ready for a review, use |
|
This lint has been nominated for inclusion. |
This comment has been minimized.
This comment has been minimized.
I have trimmed the PR description. I apologize if this came off as slop. I actually spent quite a bit of time writing it because I wanted to present the mathematical motivation for the lint. I felt that it would help contextualize what I felt was the necessity of the rule and what motivated me to draft the PR. The important snippet from the original PR description can be seen below. I wrote a good portion of this, but of course yes, the AI helped me fill it out better than I could have my self. Mathematical Motivation for this rule## Canonical layoutsMathematical motivation. This lint's value is more than stylistic. Combined with the convention of The freedom problemGiven N symbols to organize into files, most partitions retain Even under one-per-symbol, a residual freedom remains: a definition can Formal interaction with
|
fd0d22e to
68f915c
Compare
This comment has been minimized.
This comment has been minimized.
68f915c to
5071fcf
Compare
|
@rustbot ready |
a65644b to
ae0b448
Compare
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
ae0b448 to
f4fad3c
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
f4fad3c to
044f840
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
There was a problem hiding this comment.
Sorry this took so long.
Could you amend the commit for "1.99.0" and force-push? You can merge the PR afterwards.
@rustbot delegate
|
✌️ @corygabrielsen, you can now merge this pull request! If @samueltardieu told you to merge after making some further change, then please make that change and post |
Flags definitions (struct, enum, fn, impl, trait, etc.) in `mod.rs` files. Encourages putting each definition in its own named file so filenames are descriptive and unique. `lib.rs` and `main.rs` are not checked, since defining a small crate's API there is common and reasonable. Filenames are resolved through the source map so `#[path]` is handled by the real filename. `#[macro_export]` macros and inline modules are exempt. Items produced by macro expansion are skipped. Projects opting into this lint will typically also `allow(module_inception)`, since enforcing declarations-only in `mod.rs` makes `foo/foo.rs` the expected layout. Category: `restriction`. changelog: new lint: [`definition_in_module_root`] Co-authored-by: Samuel Tardieu <sam@rfc1149.net>
044f840 to
518f8ea
Compare
|
(since you were so fast to push the updated commit I was able to enable the merge myself, no need to do it) |
View all comments
Adds a restriction lint that flags item definitions (struct, enum, fn,
impl, trait, etc.) in
mod.rsfiles, somod.rsis reserved fordeclarations and re-exports.
lib.rsandmain.rsare not checked#[macro_export]macros and macro-expanded items are skipped#[path]is resolved via the source mapchangelog: new lint: [
definition_in_module_root]