rust-lang / rust-lang/rust-clippy
[lint] Impl Ordering within file
Open
Nobody has claimed this yet.
A-lint
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Does this exist already? I'd like it for large files to have standard ordering?
Impls following standard orders e.g. (all alphabetical?)
- Inherent
- Standard lib
- External crate
- Custom
Advantage
- Large files follow standard patterns
Drawbacks
Maybe as an opt in with config, because:
- Maybe you dont want this?
- Maybe bad for multiple structs in a file?
- Impls in other files
- It's already somewhere and I'm blind?
- Most important functional impls manually still need to be at the top?
Example
struct MyType {
value: i32,
}
// 1. External crate trait appears first
impl serde::Serialize for MyType { /* ... */ }
// 2. Custom trait appears before standard library traits
impl MyTrait for MyType { /* ... */ }
// 3. Standard library traits are out of alphabetical order
impl Debug for MyType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "MyType({})", self.value)
}
}
impl Clone for MyType {
fn clone(&self) -> Self {
MyType { value: self.value }
}
}
// 4. Inherent impl appears last
impl MyType {
fn new(value: i32) -> Self {
MyType { value }
}
}
Could be written as:
struct MyType {
value: i32,
}
// 1. Inherent impl
impl MyType {
fn new(value: i32) -> Self {
MyType { value }
}
}
// 2. Standard library traits (alphabetical)
impl Clone for MyType {
fn clone(&self) -> Self {
MyType { value: self.value }
}
}
impl Debug for MyType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "MyType({})", self.value)
}
}
// 3. External crate traits (alphabetical)
impl serde::Serialize for MyType { /* ... */ }
// 4. Custom traits (alphabetical)
impl MyTrait for MyType { /* ... */ }
Comparison with existing lints
No response
Additional Context
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
No implementation files, tests, or entry points are named. Start by checking whether an existing Clippy lint supports ordering impl blocks, then define the ordering rules and configuration behavior; done means the requested ordering is consistently checked with clear handling for the listed edge cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100