]>
Commit | Line | Data |
---|---|---|
60c5eb7d | 1 | An associated type binding was done outside of the type parameter declaration |
dfeec247 XL |
2 | and `where` clause. |
3 | ||
4 | Erroneous code example: | |
60c5eb7d XL |
5 | |
6 | ```compile_fail,E0229 | |
7 | pub trait Foo { | |
8 | type A; | |
9 | fn boo(&self) -> <Self as Foo>::A; | |
10 | } | |
11 | ||
12 | struct Bar; | |
13 | ||
14 | impl Foo for isize { | |
15 | type A = usize; | |
16 | fn boo(&self) -> usize { 42 } | |
17 | } | |
18 | ||
19 | fn baz<I>(x: &<I as Foo<A=Bar>>::A) {} | |
20 | // error: associated type bindings are not allowed here | |
21 | ``` | |
22 | ||
23 | To solve this error, please move the type bindings in the type parameter | |
24 | declaration: | |
25 | ||
26 | ``` | |
27 | # struct Bar; | |
28 | # trait Foo { type A; } | |
29 | fn baz<I: Foo<A=Bar>>(x: &<I as Foo>::A) {} // ok! | |
30 | ``` | |
31 | ||
32 | Or in the `where` clause: | |
33 | ||
34 | ``` | |
35 | # struct Bar; | |
36 | # trait Foo { type A; } | |
37 | fn baz<I>(x: &<I as Foo>::A) where I: Foo<A=Bar> {} | |
38 | ``` |