]> git.lizzy.rs Git - rust.git/blob - src/docs/mismatching_type_param_order.txt
Auto merge of #9425 - kraktus:patch-1, r=xFrednet
[rust.git] / src / docs / mismatching_type_param_order.txt
1 ### What it does
2 Checks for type parameters which are positioned inconsistently between
3 a type definition and impl block. Specifically, a parameter in an impl
4 block which has the same name as a parameter in the type def, but is in
5 a different place.
6
7 ### Why is this bad?
8 Type parameters are determined by their position rather than name.
9 Naming type parameters inconsistently may cause you to refer to the
10 wrong type parameter.
11
12 ### Limitations
13 This lint only applies to impl blocks with simple generic params, e.g.
14 `A`. If there is anything more complicated, such as a tuple, it will be
15 ignored.
16
17 ### Example
18 ```
19 struct Foo<A, B> {
20     x: A,
21     y: B,
22 }
23 // inside the impl, B refers to Foo::A
24 impl<B, A> Foo<B, A> {}
25 ```
26 Use instead:
27 ```
28 struct Foo<A, B> {
29     x: A,
30     y: B,
31 }
32 impl<A, B> Foo<A, B> {}
33 ```