-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add repeated_where_clause_or_trait_bound
lint
#8703
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#![deny(clippy::trait_duplication_in_bounds)] | ||
#![allow(unused)] | ||
|
||
use std::collections::BTreeMap; | ||
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; | ||
|
@@ -98,4 +99,114 @@ trait FooIter: Iterator<Item = Foo> { | |
// This should not lint | ||
fn impl_trait(_: impl AsRef<str>, _: impl AsRef<str>) {} | ||
|
||
mod repeated_where_clauses_or_trait_bounds { | ||
fn bad_foo<T: Clone + Clone + Clone + Copy, U: Clone + Copy>(arg0: T, argo1: U) { | ||
unimplemented!(); | ||
} | ||
|
||
fn bad_bar<T, U>(arg0: T, arg1: U) | ||
where | ||
T: Clone + Clone + Clone + Copy, | ||
U: Clone + Copy, | ||
{ | ||
unimplemented!(); | ||
} | ||
|
||
fn good_bar<T: Clone + Copy, U: Clone + Copy>(arg0: T, arg1: U) { | ||
unimplemented!(); | ||
} | ||
|
||
fn good_foo<T, U>(arg0: T, arg1: U) | ||
where | ||
T: Clone + Copy, | ||
U: Clone + Copy, | ||
{ | ||
unimplemented!(); | ||
} | ||
|
||
trait GoodSelfTraitBound: Clone + Copy { | ||
fn f(); | ||
} | ||
|
||
trait GoodSelfWhereClause { | ||
fn f() | ||
where | ||
Self: Clone + Copy; | ||
} | ||
|
||
trait BadSelfTraitBound: Clone + Clone + Clone { | ||
fn f(); | ||
} | ||
|
||
trait BadSelfWhereClause { | ||
fn f() | ||
where | ||
Self: Clone + Clone + Clone; | ||
} | ||
|
||
trait GoodTraitBound<T: Clone + Copy, U: Clone + Copy> { | ||
fn f(); | ||
} | ||
|
||
trait GoodWhereClause<T, U> { | ||
fn f() | ||
where | ||
T: Clone + Copy, | ||
U: Clone + Copy; | ||
} | ||
|
||
trait BadTraitBound<T: Clone + Clone + Clone + Copy, U: Clone + Copy> { | ||
fn f(); | ||
} | ||
|
||
trait BadWhereClause<T, U> { | ||
fn f() | ||
where | ||
T: Clone + Clone + Clone + Copy, | ||
U: Clone + Copy; | ||
} | ||
|
||
struct GoodStructBound<T: Clone + Copy, U: Clone + Copy> { | ||
t: T, | ||
u: U, | ||
} | ||
|
||
impl<T: Clone + Copy, U: Clone + Copy> GoodTraitBound<T, U> for GoodStructBound<T, U> { | ||
// this should not warn | ||
fn f() {} | ||
} | ||
|
||
struct GoodStructWhereClause; | ||
|
||
impl<T, U> GoodTraitBound<T, U> for GoodStructWhereClause | ||
where | ||
T: Clone + Copy, | ||
U: Clone + Copy, | ||
{ | ||
// this should not warn | ||
fn f() {} | ||
} | ||
|
||
fn no_error_separate_arg_bounds(program: impl AsRef<()>, dir: impl AsRef<()>, args: &[impl AsRef<()>]) {} | ||
|
||
trait GenericTrait<T> {} | ||
|
||
// This should not warn but currently does see #8757 | ||
fn good_generic<T: GenericTrait<u64> + GenericTrait<u32>>(arg0: T) { | ||
unimplemented!(); | ||
} | ||
Comment on lines
+194
to
+197
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is the only test case that trips up rustfix, I'd suggest to move it into its own file named something like Or are there other cases that would break rustfix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, there are other cases that break rustfix. The existing lint of Example: fn bad_foo<T: Clone + Clone + Clone + Copy, U: Clone + Copy>(arg0: T, argo1: U) {
unimplemented!();
}
I can fix this issue along with #8757 . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok, that's interesting. It seems that the old lint already triggers on the cases, the newly added lint code should check for, just with a worse error message + suggestion. I think this is even worse than #8757. Since this lint is in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok will do 👍🏼 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue here #9151 |
||
|
||
fn bad_generic<T: GenericTrait<u64> + GenericTrait<u32> + GenericTrait<u64>>(arg0: T) { | ||
unimplemented!(); | ||
} | ||
|
||
mod foo { | ||
pub trait Clone {} | ||
} | ||
|
||
fn qualified_path<T: std::clone::Clone + Clone + foo::Clone>(arg0: T) { | ||
unimplemented!(); | ||
} | ||
} | ||
|
||
fn main() {} |
Uh oh!
There was an error while loading. Please reload this page.