]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_error_codes/src/error_codes/E0223.md
New upstream version 1.70.0+dfsg1
[rustc.git] / compiler / rustc_error_codes / src / error_codes / E0223.md
1 An attempt was made to retrieve an associated type, but the type was ambiguous.
2
3 Erroneous code example:
4
5 ```compile_fail,E0223
6 trait Trait { type X; }
7
8 fn main() {
9 let foo: Trait::X;
10 }
11 ```
12
13 The problem here is that we're attempting to take the associated type of `X`
14 from `Trait`. Unfortunately, the type of `X` is not defined, because it's only
15 made concrete in implementations of the trait. A working version of this code
16 might look like:
17
18 ```
19 trait Trait { type X; }
20
21 struct Struct;
22 impl Trait for Struct {
23 type X = u32;
24 }
25
26 fn main() {
27 let foo: <Struct as Trait>::X;
28 }
29 ```
30
31 This syntax specifies that we want the associated type `X` from `Struct`'s
32 implementation of `Trait`.
33
34 Due to internal limitations of the current compiler implementation we cannot
35 simply use `Struct::X`.