summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/mismatching_type_param_order.rs
blob: 40c1fcae1fd3fb172004276a8f8a8df3ae8821c6 (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
#![warn(clippy::mismatching_type_param_order)]
#![allow(clippy::disallowed_names)]

fn main() {
    struct Foo<A, B> {
        x: A,
        y: B,
    }

    // lint on both params
    impl<B, A> Foo<B, A> {}

    // lint on the 2nd param
    impl<C, A> Foo<C, A> {}

    // should not lint
    impl<A, B> Foo<A, B> {}

    struct FooLifetime<'l, 'm, A, B> {
        x: &'l A,
        y: &'m B,
    }

    // should not lint on lifetimes
    impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {}

    struct Bar {
        x: i32,
    }

    // should not lint
    impl Bar {}

    // also works for enums
    enum FooEnum<A, B, C> {
        X(A),
        Y(B),
        Z(C),
    }

    impl<C, A, B> FooEnum<C, A, B> {}

    // also works for unions
    union FooUnion<A: Copy, B>
    where
        B: Copy,
    {
        x: A,
        y: B,
    }

    impl<B: Copy, A> FooUnion<B, A> where A: Copy {}

    impl<A, B> FooUnion<A, B>
    where
        A: Copy,
        B: Copy,
    {
    }

    // if the types are complicated, do not lint
    impl<K, V, B> Foo<(K, V), B> {}
    impl<K, V, A> Foo<(K, V), A> {}
}