summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/type_repetition_in_bounds.rs
blob: 2eca1f4701c9fdaeccb0da0160b67bea538f4da1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#![deny(clippy::type_repetition_in_bounds)]

use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};

pub fn foo<T>(_t: T)
where
    T: Copy,
    T: Clone,
{
    unimplemented!();
}

pub fn bar<T, U>(_t: T, _u: U)
where
    T: Copy,
    U: Clone,
{
    unimplemented!();
}

// Threshold test (see #4380)
trait LintBounds
where
    Self: Clone,
    Self: Copy + Default + Ord,
    Self: Add<Output = Self> + AddAssign + Sub<Output = Self> + SubAssign,
    Self: Mul<Output = Self> + MulAssign + Div<Output = Self> + DivAssign,
{
}

trait LotsOfBounds
where
    Self: Clone + Copy + Default + Ord,
    Self: Add<Output = Self> + AddAssign + Sub<Output = Self> + SubAssign,
    Self: Mul<Output = Self> + MulAssign + Div<Output = Self> + DivAssign,
{
}

// Generic distinction (see #4323)
mod issue4323 {
    pub struct Foo<A>(A);
    pub struct Bar<A, B> {
        a: Foo<A>,
        b: Foo<B>,
    }

    impl<A, B> Unpin for Bar<A, B>
    where
        Foo<A>: Unpin,
        Foo<B>: Unpin,
    {
    }
}

// Extern macros shouldn't lint (see #4326)
extern crate serde;
mod issue4326 {
    use serde::{Deserialize, Serialize};

    trait Foo {}
    impl Foo for String {}

    #[derive(Debug, Serialize, Deserialize)]
    struct Bar<S>
    where
        S: Foo,
    {
        foo: S,
    }
}

// Issue #7360
struct Foo<T, U>
where
    T: Clone,
    U: Clone,
{
    t: T,
    u: U,
}

// Check for the `?` in `?Sized`
pub fn f<T: ?Sized>()
where
    T: Clone,
{
}
pub fn g<T: Clone>()
where
    T: ?Sized,
{
}

// This should not lint
fn impl_trait(_: impl AsRef<str>, _: impl AsRef<str>) {}

fn main() {}