new lint: Unused trait bound(s)
Author: taufik-ramaCreated Aug 10, 2022Updated Sep 30, 2026
LabelsA-lint
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
- It might need some thought on how it would interact with
negative_impls
- It might need some thought on how it would interact with
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()
}Source: rust-lang/rust-clippy