Rollup merge of #5852 - wiomoc:feature/lint-duplicate-trait, r=Manishearth

Add lint for duplicate methods of trait bounds

rel: #5777

changelog: Add [`trait_duplication_in_bounds`] lint
This commit is contained in:
Philipp Krones 2020-08-04 12:06:41 +02:00 committed by GitHub
commit 84455b211f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 156 additions and 2 deletions

View file

@ -0,0 +1,31 @@
#![deny(clippy::trait_duplication_in_bounds)]
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
fn bad_foo<T: Clone + Default, Z: Copy>(arg0: T, arg1: Z)
where
T: Clone,
T: Default,
{
unimplemented!();
}
fn good_bar<T: Clone + Default>(arg: T) {
unimplemented!();
}
fn good_foo<T>(arg: T)
where
T: Clone + Default,
{
unimplemented!();
}
fn good_foobar<T: Default>(arg: T)
where
T: Clone,
{
unimplemented!();
}
fn main() {}

View file

@ -0,0 +1,23 @@
error: this trait bound is already specified in the where clause
--> $DIR/trait_duplication_in_bounds.rs:5:15
|
LL | fn bad_foo<T: Clone + Default, Z: Copy>(arg0: T, arg1: Z)
| ^^^^^
|
note: the lint level is defined here
--> $DIR/trait_duplication_in_bounds.rs:1:9
|
LL | #![deny(clippy::trait_duplication_in_bounds)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: consider removing this trait bound
error: this trait bound is already specified in the where clause
--> $DIR/trait_duplication_in_bounds.rs:5:23
|
LL | fn bad_foo<T: Clone + Default, Z: Copy>(arg0: T, arg1: Z)
| ^^^^^^^
|
= help: consider removing this trait bound
error: aborting due to 2 previous errors