forked from rust-lang/rust-clippy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add lint:
could_be_assoc_type_bounds
- Loading branch information
Showing
20 changed files
with
1,046 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
//@aux-build:proc_macros.rs | ||
#![allow(clippy::extra_unused_type_parameters)] | ||
|
||
extern crate proc_macros; | ||
|
||
fn projection_with_existing_assoc_bounds<T>() | ||
where | ||
T: Iterator<Item: Clone + Copy + Sized>, | ||
|
||
//~^ could_be_assoc_type_bounds | ||
{ | ||
} | ||
|
||
fn projection_with_existing_bounds<T: Iterator<Item: Clone + Copy + Sized>>() | ||
//~^ could_be_assoc_type_bounds | ||
{ | ||
} | ||
|
||
fn no_fully_qualified_path<T: Iterator<Item: Clone>>() | ||
where | ||
// False negative for now: `T::Item` has a `Res::Err` resolution | ||
T::Item: Copy + Sized, | ||
{ | ||
} | ||
|
||
fn ty_param<T: Iterator<Item: Clone>, >() {} | ||
|
||
fn multiple_projections<T>() | ||
where | ||
T: Iterator<Item: Sized + Clone>, | ||
|
||
{ | ||
} | ||
|
||
fn ty_param_used_in_body<T: Iterator<Item = P>, P: Clone + Default>() { | ||
P::default(); | ||
} | ||
|
||
fn nested_impl_trait(_: impl Iterator<Item = impl Sized>) {} | ||
|
||
fn impl_trait_generic(_: impl Iterator<Item: Copy>) {} | ||
|
||
fn single_impl_trait(_: impl Iterator<Item = ()>) {} | ||
|
||
fn parenthesized<T: Iterator<Item: Fn()>, >() {} //~ could_be_assoc_type_bounds | ||
|
||
// Make sure implicit generic lifetime parameters for delim doesn't mess up spans | ||
pub fn elided_lifetime<I, >(iter: I, delim: &str) | ||
where | ||
I: IntoIterator<Item: std::fmt::Display>, | ||
//~ could_be_assoc_type_bounds | ||
{ | ||
} | ||
|
||
fn parenthesized2<F: Fn()>() | ||
where | ||
F::Output: Copy, | ||
{ | ||
} | ||
fn many_ty_params<T, X>() | ||
//~^ could_be_assoc_type_bounds | ||
where | ||
T: Iterator<Item: Copy>, | ||
{ | ||
} | ||
|
||
#[clippy::msrv = "1.78.0"] | ||
fn low_msrv<T: Iterator<Item = P>, P: Copy + Default>() { | ||
#[clippy::msrv = "1.79.0"] | ||
P::default(); | ||
} | ||
|
||
// More involved test case with multiple associated types and generic parameters | ||
trait Trait1<G1, G2>: Default { | ||
type A2; | ||
type A3; | ||
type A4; | ||
} | ||
|
||
fn complex<T, G1, G2>() | ||
where | ||
(T, T): Trait1<G1, G2, A2 = u32, A3: Clone, A4: Clone>, | ||
|
||
{ | ||
} | ||
|
||
proc_macros::external! { | ||
fn external<T: Iterator<Item = I>, I: Copy>() {} | ||
} | ||
proc_macros::with_span! { | ||
span | ||
fn external2<T: Iterator<Item = I>, I: Copy>() {} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
//@aux-build:proc_macros.rs | ||
#![allow(clippy::extra_unused_type_parameters)] | ||
|
||
extern crate proc_macros; | ||
|
||
fn projection_with_existing_assoc_bounds<T>() | ||
where | ||
T: Iterator<Item: Clone>, | ||
<T as Iterator>::Item: Copy + Sized, | ||
//~^ could_be_assoc_type_bounds | ||
{ | ||
} | ||
|
||
fn projection_with_existing_bounds<T: Iterator<Item: Clone>>() | ||
where | ||
<T as Iterator>::Item: Copy + Sized, | ||
//~^ could_be_assoc_type_bounds | ||
{ | ||
} | ||
|
||
fn no_fully_qualified_path<T: Iterator<Item: Clone>>() | ||
where | ||
// False negative for now: `T::Item` has a `Res::Err` resolution | ||
T::Item: Copy + Sized, | ||
{ | ||
} | ||
|
||
fn ty_param<T: Iterator<Item = P>, P: Clone>() {} | ||
|
||
fn multiple_projections<T>() | ||
where | ||
T: Iterator, | ||
<T as Iterator>::Item: Sized, | ||
//~^ could_be_assoc_type_bounds | ||
<T as Iterator>::Item: Clone, | ||
{ | ||
} | ||
|
||
fn ty_param_used_in_body<T: Iterator<Item = P>, P: Clone + Default>() { | ||
P::default(); | ||
} | ||
|
||
fn nested_impl_trait(_: impl Iterator<Item = impl Sized>) {} | ||
|
||
fn impl_trait_generic<T: Copy>(_: impl Iterator<Item = T>) {} | ||
|
||
fn single_impl_trait(_: impl Iterator<Item = ()>) {} | ||
|
||
fn parenthesized<T: Iterator<Item = F>, F: Fn()>() {} //~ could_be_assoc_type_bounds | ||
|
||
// Make sure implicit generic lifetime parameters for delim doesn't mess up spans | ||
pub fn elided_lifetime<I, T>(iter: I, delim: &str) | ||
where | ||
I: IntoIterator<Item = T>, | ||
T: std::fmt::Display, //~ could_be_assoc_type_bounds | ||
{ | ||
} | ||
|
||
fn parenthesized2<F: Fn()>() | ||
where | ||
F::Output: Copy, | ||
{ | ||
} | ||
fn many_ty_params<T, U: Copy, X>() | ||
//~^ could_be_assoc_type_bounds | ||
where | ||
T: Iterator<Item = U>, | ||
{ | ||
} | ||
|
||
#[clippy::msrv = "1.78.0"] | ||
fn low_msrv<T: Iterator<Item = P>, P: Copy + Default>() { | ||
#[clippy::msrv = "1.79.0"] | ||
P::default(); | ||
} | ||
|
||
// More involved test case with multiple associated types and generic parameters | ||
trait Trait1<G1, G2>: Default { | ||
type A2; | ||
type A3; | ||
type A4; | ||
} | ||
|
||
fn complex<T, U, G1, G2>() | ||
where | ||
(T, T): Trait1<G1, G2, A2 = u32, A3 = U>, | ||
<(T, T) as Trait1<G1, G2>>::A4: Clone, | ||
//~^ could_be_assoc_type_bounds | ||
U: Clone, | ||
{ | ||
} | ||
|
||
proc_macros::external! { | ||
fn external<T: Iterator<Item = I>, I: Copy>() {} | ||
} | ||
proc_macros::with_span! { | ||
span | ||
fn external2<T: Iterator<Item = I>, I: Copy>() {} | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.