]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0229.md
Rollup merge of #67875 - dtolnay:hidden, r=GuillaumeGomez
[rust.git] / src / librustc_error_codes / error_codes / E0229.md
1 An associated type binding was done outside of the type parameter declaration
2 and `where` clause. Erroneous code example:
3
4 ```compile_fail,E0229
5 pub trait Foo {
6     type A;
7     fn boo(&self) -> <Self as Foo>::A;
8 }
9
10 struct Bar;
11
12 impl Foo for isize {
13     type A = usize;
14     fn boo(&self) -> usize { 42 }
15 }
16
17 fn baz<I>(x: &<I as Foo<A=Bar>>::A) {}
18 // error: associated type bindings are not allowed here
19 ```
20
21 To solve this error, please move the type bindings in the type parameter
22 declaration:
23
24 ```
25 # struct Bar;
26 # trait Foo { type A; }
27 fn baz<I: Foo<A=Bar>>(x: &<I as Foo>::A) {} // ok!
28 ```
29
30 Or in the `where` clause:
31
32 ```
33 # struct Bar;
34 # trait Foo { type A; }
35 fn baz<I>(x: &<I as Foo>::A) where I: Foo<A=Bar> {}
36 ```