diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-03-28 07:01:08 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-28 07:01:08 +0200 |
| commit | eee3f484f9c03e8e702cc8af90c0a35f902272d0 (patch) | |
| tree | 5e8221182055846234a0c76a6a76500ee19a1fbf /compiler/rustc_error_codes/src | |
| parent | a7c07cf7315c8ed74723d0e251ef01847e75a892 (diff) | |
| parent | 3c4fabc341c1fa854104b95a8daf8465a3c50a7a (diff) | |
| download | rust-eee3f484f9c03e8e702cc8af90c0a35f902272d0.tar.gz rust-eee3f484f9c03e8e702cc8af90c0a35f902272d0.zip | |
Rollup merge of #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
Diffstat (limited to 'compiler/rustc_error_codes/src')
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0223.md | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0223.md b/compiler/rustc_error_codes/src/error_codes/E0223.md index 0d49f514ccf..ba5f0052821 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0223.md +++ b/compiler/rustc_error_codes/src/error_codes/E0223.md @@ -3,31 +3,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; } +trait Trait { type X; } fn main() { - let foo: MyTrait::X; + let foo: Trait::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: +The problem here is that we're attempting to take the associated type of `X` +from `Trait`. 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; +trait Trait { type X; } -impl MyTrait for MyStruct { +struct Struct; +impl Trait for Struct { type X = u32; } fn main() { - let foo: <MyStruct as MyTrait>::X; + let foo: <Struct as Trait>::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. +This syntax specifies that we want the associated type `X` from `Struct`'s +implementation of `Trait`. + +Due to internal limitations of the current compiler implementation we cannot +simply use `Struct::X`. |
