rust-lang / rust-lang/rust-clippy
Stop suggesting alphabetic arrangement between different types of items (structs vs funcs vs mods etc)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
I think that arbitrary_source_item_ordering should stop comparing names that belong to different types of items.
For example I want main() to always be at the top, and I want mod tests {} to always be at the bottom. But if I have an function called send_to_database(), this lint will send me an annoying suggestion to "put mod tests {} before send_to_database(). Yet turning off this lint entirely isn't desirable either because it's valuable to have items of the same type arranged alphabetically (for example fields in a struct).
Lint Name
arbitrary_source_item_ordering
Reproducer
I tried this code:
fn main() {
let structy = Structy::default();
let _field1 = structy.field1();
let _field_one = Structy::field1(&structy);
}
#[derive(Default)]
pub(crate) struct Structy {
field1: String,
}
impl Structy {
pub(crate) fn field1(&self) -> &String {
&self.field1
}
}
I saw this happen:
incorrect ordering of items (module item groupings specify another order)
I expected to see this happen:
silence
Version
rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1
Additional Labels
No response
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
The affected lint is arbitrary_source_item_ordering; start by locating its implementation and existing tests in rust-clippy. Reproduce the reported grouping warning, then verify that ordering checks remain for items of the same type while cross-type comparisons no longer produce suggestions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100