summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_error_codes/src/error_codes/E0223.md
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_error_codes/src/error_codes/E0223.md')
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0223.md33
1 files changed, 33 insertions, 0 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0223.md b/compiler/rustc_error_codes/src/error_codes/E0223.md
new file mode 100644
index 000000000..0d49f514c
--- /dev/null
+++ b/compiler/rustc_error_codes/src/error_codes/E0223.md
@@ -0,0 +1,33 @@
+An attempt was made to retrieve an associated type, but the type was ambiguous.
+
+Erroneous code example:
+
+```compile_fail,E0223
+trait MyTrait {type X; }
+
+fn main() {
+ let foo: MyTrait::X;
+}
+```
+
+The problem here is that we're attempting to take the type of X from MyTrait.
+Unfortunately, the type of X is not defined, because it's only made concrete in
+implementations of the trait. A working version of this code might look like:
+
+```
+trait MyTrait {type X; }
+struct MyStruct;
+
+impl MyTrait for MyStruct {
+ type X = u32;
+}
+
+fn main() {
+ let foo: <MyStruct as MyTrait>::X;
+}
+```
+
+This syntax specifies that we want the X type from MyTrait, as made concrete in
+MyStruct. The reason that we cannot simply use `MyStruct::X` is that MyStruct
+might implement two different traits with identically-named associated types.
+This syntax allows disambiguation between the two.