|
| 1 | +//@aux-build:proc_macros.rs |
| 2 | +#![allow(clippy::extra_unused_type_parameters)] |
| 3 | + |
| 4 | +extern crate proc_macros; |
| 5 | + |
| 6 | +fn projection_with_existing_assoc_bounds<T>() |
| 7 | +where |
| 8 | + T: Iterator<Item: Clone>, |
| 9 | + <T as Iterator>::Item: Copy + Sized, |
| 10 | + //~^ could_be_assoc_type_bounds |
| 11 | +{ |
| 12 | +} |
| 13 | + |
| 14 | +fn projection_with_existing_bounds<T: Iterator<Item: Clone>>() |
| 15 | +where |
| 16 | + <T as Iterator>::Item: Copy + Sized, |
| 17 | + //~^ could_be_assoc_type_bounds |
| 18 | +{ |
| 19 | +} |
| 20 | + |
| 21 | +fn no_fully_qualified_path<T: Iterator<Item: Clone>>() |
| 22 | +where |
| 23 | + // False negative for now: `T::Item` has a `Res::Err` resolution |
| 24 | + T::Item: Copy + Sized, |
| 25 | +{ |
| 26 | +} |
| 27 | + |
| 28 | +fn ty_param<T: Iterator<Item = P>, P: Clone>() {} |
| 29 | + |
| 30 | +fn multiple_projections<T>() |
| 31 | +where |
| 32 | + T: Iterator, |
| 33 | + <T as Iterator>::Item: Sized, |
| 34 | + //~^ could_be_assoc_type_bounds |
| 35 | + <T as Iterator>::Item: Clone, |
| 36 | +{ |
| 37 | +} |
| 38 | + |
| 39 | +fn ty_param_used_in_body<T: Iterator<Item = P>, P: Clone + Default>() { |
| 40 | + P::default(); |
| 41 | +} |
| 42 | + |
| 43 | +fn nested_impl_trait(_: impl Iterator<Item = impl Sized>) {} |
| 44 | + |
| 45 | +fn impl_trait_generic<T: Copy>(_: impl Iterator<Item = T>) {} |
| 46 | + |
| 47 | +fn single_impl_trait(_: impl Iterator<Item = ()>) {} |
| 48 | + |
| 49 | +fn parenthesized<T: Iterator<Item = F>, F: Fn()>() {} //~ could_be_assoc_type_bounds |
| 50 | + |
| 51 | +// Make sure implicit generic lifetime parameters for delim doesn't mess up spans |
| 52 | +pub fn elided_lifetime<I, T>(iter: I, delim: &str) |
| 53 | +where |
| 54 | + I: IntoIterator<Item = T>, |
| 55 | + T: std::fmt::Display, //~ could_be_assoc_type_bounds |
| 56 | +{ |
| 57 | +} |
| 58 | + |
| 59 | +fn parenthesized2<F: Fn()>() |
| 60 | +where |
| 61 | + F::Output: Copy, |
| 62 | +{ |
| 63 | +} |
| 64 | +fn many_ty_params<T, U: Copy, X>() |
| 65 | +//~^ could_be_assoc_type_bounds |
| 66 | +where |
| 67 | + T: Iterator<Item = U>, |
| 68 | +{ |
| 69 | +} |
| 70 | + |
| 71 | +#[clippy::msrv = "1.78.0"] |
| 72 | +fn low_msrv<T: Iterator<Item = P>, P: Copy + Default>() { |
| 73 | + #[clippy::msrv = "1.79.0"] |
| 74 | + P::default(); |
| 75 | +} |
| 76 | + |
| 77 | +// More involved test case with multiple associated types and generic parameters |
| 78 | +trait Trait1<G1, G2>: Default { |
| 79 | + type A2; |
| 80 | + type A3; |
| 81 | + type A4; |
| 82 | +} |
| 83 | + |
| 84 | +fn complex<T, U, G1, G2>() |
| 85 | +where |
| 86 | + (T, T): Trait1<G1, G2, A2 = u32, A3 = U>, |
| 87 | + <(T, T) as Trait1<G1, G2>>::A4: Clone, |
| 88 | + //~^ could_be_assoc_type_bounds |
| 89 | + U: Clone, |
| 90 | +{ |
| 91 | +} |
| 92 | + |
| 93 | +proc_macros::external! { |
| 94 | + fn external<T: Iterator<Item = I>, I: Copy>() {} |
| 95 | +} |
| 96 | +proc_macros::with_span! { |
| 97 | + span |
| 98 | + fn external2<T: Iterator<Item = I>, I: Copy>() {} |
| 99 | +} |
| 100 | + |
| 101 | +fn main() {} |
0 commit comments