rust-lang / rust-lang/rust-clippy

new lint: Unused trait bound(s)

Open
#9,316 7 comments 16 reactions 0 assignees View on GitHub

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

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
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()
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No implementation files, tests, or entry points are identified in the issue. Start by reviewing the proposed lint behavior and the linked Rust negative_impls discussion, then determine the relevant Clippy lint location and test pattern. Done means the lint reliably warns for unused trait bounds while accounting for the API and negative-impl concerns described here.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.