rust-clippy
rust-clippy copied to clipboard
new lint: Unused trait bound(s)
What it does
For any trait bounds that's not used on the function body, create an "unused" warning
Lint Name
unused_trait_bound
Category
pedantic
Advantage
- More "tight" code, we can be sure that each bounds will be used
- and maybe in other words: more cleaner code since unused bound can be safely deleted
Drawbacks
- Might not be suitable for library APIs, since removing bounds (even if it's unused) might be a breaking change
Example
trait Database {
fn database(&self);
}
trait Redis {
fn redis(&self);
}
fn get_user<C>(conn: C)
where
C: Database + Redis, // this `Redis` bound should be warned
{
// we just so happen to forgot to check for Redis cache
conn.database()
}
Could be written as:
trait Database {
fn database(&self);
}
trait Redis {
fn redis(&self);
}
fn get_user<C>(conn: C)
where
C: Database, // either remove the bound, or
{
// use the bound
// conn.redis()
conn.database()
}