]> git.lizzy.rs Git - rust.git/blob - tests/ui/mismatching_type_param_order.rs
Auto merge of #9684 - kraktus:ref_option_ref, r=xFrednet
[rust.git] / tests / ui / mismatching_type_param_order.rs
1 #![warn(clippy::mismatching_type_param_order)]
2 #![allow(clippy::disallowed_names)]
3
4 fn main() {
5     struct Foo<A, B> {
6         x: A,
7         y: B,
8     }
9
10     // lint on both params
11     impl<B, A> Foo<B, A> {}
12
13     // lint on the 2nd param
14     impl<C, A> Foo<C, A> {}
15
16     // should not lint
17     impl<A, B> Foo<A, B> {}
18
19     struct FooLifetime<'l, 'm, A, B> {
20         x: &'l A,
21         y: &'m B,
22     }
23
24     // should not lint on lifetimes
25     impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {}
26
27     struct Bar {
28         x: i32,
29     }
30
31     // should not lint
32     impl Bar {}
33
34     // also works for enums
35     enum FooEnum<A, B, C> {
36         X(A),
37         Y(B),
38         Z(C),
39     }
40
41     impl<C, A, B> FooEnum<C, A, B> {}
42
43     // also works for unions
44     union FooUnion<A: Copy, B>
45     where
46         B: Copy,
47     {
48         x: A,
49         y: B,
50     }
51
52     impl<B: Copy, A> FooUnion<B, A> where A: Copy {}
53
54     impl<A, B> FooUnion<A, B>
55     where
56         A: Copy,
57         B: Copy,
58     {
59     }
60
61     // if the types are complicated, do not lint
62     impl<K, V, B> Foo<(K, V), B> {}
63     impl<K, V, A> Foo<(K, V), A> {}
64 }