rust-lang / rust-lang/rust-clippy
Lint to check unnecessary trait bounds
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
Some trait bounds aren't required, though they may be added for semantic purposes, this is rare. An example is say we have this function:
async fn<T: Send + Sync>foo() { ... }
then it no longer needs async so we change it to
fn<T: Send + Sync>foo() { ... }
but we forgot to remove the Send + Sync bounds and they slip unnoticed, this is bad because users can no longer use types that don't implement Send + Sync even though they actually can
Lint Name
unnecessary_trait_bounds
Category
correctness
Advantage
- Removes unnecessary restrictions
- Makes code more clear
- Possibly even frees a dependency if the trait is from a crate and it's not used otherwsie
Drawbacks
Basically warns on almost every trait bound in struct definitions:
struct<T: Send> Foo<T> { ... }
Whether this is good design is controversial, this could be separated to another lint but I don't see it necessary as users can simply allow it
Example
fn print<T: Debug + Display>(x: T) {
println!("{x:?}");
}
Could be written as:
fn print<T: Debug>(x: T) {
println!("{x:?}");
}
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 with the issue's Rust examples and define which unused trait bounds the lint should report, including whether struct definitions are in scope. Resolve the stated design concern about controversial warnings before implementing it, then add coverage demonstrating that unnecessary bounds are reported while required bounds remain accepted.
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
- Mostly clear
- Newbie friendliness
- 35/100