Skip to content

Commit eee3f48

Browse files
authored
Rollup merge of rust-lang#109565 - WaffleLapkin:better_docs_for_e0223, r=oli-obk
Improve documentation for E0223 See discussion in https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Inconsistency.20in.20prohibiting.20.60Type.3A.3AAssocType.60
2 parents a7c07cf + 3c4fabc commit eee3f48

File tree

1 file changed

+15
-13
lines changed
  • compiler/rustc_error_codes/src/error_codes

1 file changed

+15
-13
lines changed

compiler/rustc_error_codes/src/error_codes/E0223.md

+15-13
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,33 @@ An attempt was made to retrieve an associated type, but the type was ambiguous.
33
Erroneous code example:
44

55
```compile_fail,E0223
6-
trait MyTrait {type X; }
6+
trait Trait { type X; }
77
88
fn main() {
9-
let foo: MyTrait::X;
9+
let foo: Trait::X;
1010
}
1111
```
1212

13-
The problem here is that we're attempting to take the type of X from MyTrait.
14-
Unfortunately, the type of X is not defined, because it's only made concrete in
15-
implementations of the trait. A working version of this code might look like:
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:
1617

1718
```
18-
trait MyTrait {type X; }
19-
struct MyStruct;
19+
trait Trait { type X; }
2020
21-
impl MyTrait for MyStruct {
21+
struct Struct;
22+
impl Trait for Struct {
2223
type X = u32;
2324
}
2425
2526
fn main() {
26-
let foo: <MyStruct as MyTrait>::X;
27+
let foo: <Struct as Trait>::X;
2728
}
2829
```
2930

30-
This syntax specifies that we want the X type from MyTrait, as made concrete in
31-
MyStruct. The reason that we cannot simply use `MyStruct::X` is that MyStruct
32-
might implement two different traits with identically-named associated types.
33-
This syntax allows disambiguation between the two.
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`.

0 commit comments

Comments
 (0)