Skip to content

Commit c1e865c

Browse files
committed
Auto merge of #27838 - AlisdairO:diagnostics221, r=Manishearth
As title :-) Part of #24407. r? @Manishearth
2 parents e7261f3 + de26d5e commit c1e865c

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/librustc_typeck/diagnostics.rs

+36-1
Original file line numberDiff line numberDiff line change
@@ -2229,6 +2229,42 @@ type Foo = Trait<Bar=i32>; // ok!
22292229
```
22302230
"##,
22312231

2232+
E0221: r##"
2233+
An attempt was made to retrieve an associated type, but the type was ambiguous.
2234+
For example:
2235+
2236+
```
2237+
trait T1 {}
2238+
trait T2 {}
2239+
2240+
trait Foo {
2241+
type A: T1;
2242+
}
2243+
2244+
trait Bar : Foo {
2245+
type A: T2;
2246+
fn do_something() {
2247+
let _: Self::A;
2248+
}
2249+
}
2250+
```
2251+
2252+
In this example, `Foo` defines an associated type `A`. `Bar` inherits that type
2253+
from `Foo`, and defines another associated type of the same name. As a result,
2254+
when we attempt to use `Self::A`, it's ambiguous whether we mean the `A` defined
2255+
by `Foo` or the one defined by `Bar`.
2256+
2257+
There are two options to work around this issue. The first is simply to rename
2258+
one of the types. Alternatively, one can specify the intended type using the
2259+
following syntax:
2260+
2261+
```
2262+
fn do_something() {
2263+
let _: <Self as Bar>::A;
2264+
}
2265+
```
2266+
"##,
2267+
22322268
E0223: r##"
22332269
An attempt was made to retrieve an associated type, but the type was ambiguous.
22342270
For example:
@@ -2698,7 +2734,6 @@ register_diagnostics! {
26982734
E0217, // ambiguous associated type, defined in multiple supertraits
26992735
E0218, // no associated type defined
27002736
E0219, // associated type defined in higher-ranked supertrait
2701-
E0221, // ambiguous associated type in bounds
27022737
// E0222, // Error code E0045 (variadic function must have C calling
27032738
// convention) duplicate
27042739
E0224, // at least one non-builtin train is required for an object type

0 commit comments

Comments
 (0)