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