]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0223.md
Rollup merge of #62514 - stephaneyfx:box-ffi, r=nikomatsakis
[rust.git] / src / librustc_error_codes / error_codes / E0223.md
1 An attempt was made to retrieve an associated type, but the type was ambiguous.
2 For example:
3
4 ```compile_fail,E0223
5 trait MyTrait {type X; }
6
7 fn main() {
8     let foo: MyTrait::X;
9 }
10 ```
11
12 The problem here is that we're attempting to take the type of X from MyTrait.
13 Unfortunately, the type of X is not defined, because it's only made concrete in
14 implementations of the trait. A working version of this code might look like:
15
16 ```
17 trait MyTrait {type X; }
18 struct MyStruct;
19
20 impl MyTrait for MyStruct {
21     type X = u32;
22 }
23
24 fn main() {
25     let foo: <MyStruct as MyTrait>::X;
26 }
27 ```
28
29 This syntax specifies that we want the X type from MyTrait, as made concrete in
30 MyStruct. The reason that we cannot simply use `MyStruct::X` is that MyStruct
31 might implement two different traits with identically-named associated types.
32 This syntax allows disambiguation between the two.