Skip to content

Detect duplicate trait bounds #90108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pierwill opened this issue Oct 20, 2021 · 4 comments
Closed

Detect duplicate trait bounds #90108

pierwill opened this issue Oct 20, 2021 · 4 comments
Assignees
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pierwill
Copy link
Member

pierwill commented Oct 20, 2021

We might look for a way to detect, and possibly remove, repeated trait bounds. Maybe as a lint? Or maybe this would be better in rustfmt or clippy?

An example from #87880:

pub trait ControlFlowGraph:
    DirectedGraph + WithStartNode + WithPredecessors + WithStartNode + WithSuccessors + WithNumNodes

I was surprised this is allowed!

Playground example:

pub trait DirectedGraph {}
pub trait WithStartNode {}
pub trait WithPredecessors {}
pub trait WithSuccessors {}
pub trait WithNumNodes {}

pub trait ControlFlowGraph:
    DirectedGraph + WithStartNode + WithPredecessors + WithStartNode + WithSuccessors + WithNumNodes
{}
@pierwill
Copy link
Member Author

@estebank: Would this make sense as a lint in compiler/rustc_lint/src/traits.rs, or would clippy be better?

@pierwill
Copy link
Member Author

@rustbot label +A-lint

@rustbot rustbot added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Mar 16, 2022
@estebank
Copy link
Contributor

I think this would be ok in the compiler itself (@rust-lang/compiler any reason not to accept such a lint? this would require a proposal?), but it would certainly be reasonable in clippy. You can start working on either codebase that is easiest for you (which might be clippy) and migrate it to the other, as they both use rustc's linting and visitor machinery, so this can be linted almost the same in both.

@pierwill
Copy link
Member Author

@rustbot claim

@fmease fmease added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. labels Dec 21, 2024
@fmease fmease added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Apr 20, 2025
@fmease fmease closed this as completed Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants