Skip to content
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

Lint on duplicate trait bound #88013

Open
Aaron1011 opened this issue Aug 13, 2021 · 5 comments
Open

Lint on duplicate trait bound #88013

Aaron1011 opened this issue Aug 13, 2021 · 5 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

Aaron1011 commented Aug 13, 2021

The following code compiles without any warnings:

pub trait Foo {}

pub fn bar<T: Foo + Foo>() {}

We should lint on the duplicate Foo bound.

@Aaron1011 Aaron1011 added A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 13, 2021
@ibraheemdev
Copy link
Member

Clippy catches this:

#![deny(clippy::pedantic)]

pub trait Foo {}

pub fn bar<T: Foo>() where T: Foo {}
error: this trait bound is already specified in the where clause
 --> src/lib.rs:5:15
  |
5 | pub fn bar<T: Foo>() where T: Foo {}
  |               ^^^
  |
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![deny(clippy::pedantic)]
  |         ^^^^^^^^^^^^^^^^
  = note: `#[deny(clippy::trait_duplication_in_bounds)]` implied by `#[deny(clippy::pedantic)]`
  = help: consider removing this trait bound
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trait_duplication_in_bounds

@Aaron1011
Copy link
Member Author

I think it would be useful to uplift this lint into rustc.

@ibraheemdev
Copy link
Member

It catches when multiple syntaxes are being used to specify a bound, but not when the same is being used twice. ie: fn foo<T: Clone>() where T: Clone fails, but fn foo<T: Clone + Clone>() does not. Should the lint be modified to catch this as well, or should a new lint be created separately?

@Aaron1011
Copy link
Member Author

Including both in the same lint sounds reasonable.

@ibraheemdev
Copy link
Member

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system 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.

2 participants