]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0221.md
Auto merge of #66396 - smmalis37:pythontest, r=alexcrichton
[rust.git] / src / librustc_error_codes / error_codes / E0221.md
1 An attempt was made to retrieve an associated type, but the type was ambiguous.
2 For example:
3
4 ```compile_fail,E0221
5 trait T1 {}
6 trait T2 {}
7
8 trait Foo {
9     type A: T1;
10 }
11
12 trait Bar : Foo {
13     type A: T2;
14     fn do_something() {
15         let _: Self::A;
16     }
17 }
18 ```
19
20 In this example, `Foo` defines an associated type `A`. `Bar` inherits that type
21 from `Foo`, and defines another associated type of the same name. As a result,
22 when we attempt to use `Self::A`, it's ambiguous whether we mean the `A` defined
23 by `Foo` or the one defined by `Bar`.
24
25 There are two options to work around this issue. The first is simply to rename
26 one of the types. Alternatively, one can specify the intended type using the
27 following syntax:
28
29 ```
30 trait T1 {}
31 trait T2 {}
32
33 trait Foo {
34     type A: T1;
35 }
36
37 trait Bar : Foo {
38     type A: T2;
39     fn do_something() {
40         let _: <Self as Bar>::A;
41     }
42 }
43 ```