Skip to content

Commit dce1863

Browse files
committed
Rollup merge of #27212 - AlisdairO:diagnostics225, r=Manishearth
As title! Part of #24407. r? @Manishearth
2 parents 9219182 + dd3ac90 commit dce1863

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

src/librustc_typeck/diagnostics.rs

+56-2
Original file line numberDiff line numberDiff line change
@@ -1895,6 +1895,62 @@ type Foo = Trait<Bar=i32>; // ok!
18951895
```
18961896
"##,
18971897

1898+
E0223: r##"
1899+
An attempt was made to retrieve an associated type, but the type was ambiguous.
1900+
For example:
1901+
1902+
```
1903+
trait MyTrait {type X; }
1904+
1905+
fn main() {
1906+
let foo: MyTrait::X;
1907+
}
1908+
```
1909+
1910+
The problem here is that we're attempting to take the type of X from MyTrait.
1911+
Unfortunately, the type of X is not defined, because it's only made concrete in
1912+
implementations of the trait. A working version of this code might look like:
1913+
1914+
```
1915+
trait MyTrait {type X; }
1916+
struct MyStruct;
1917+
1918+
impl MyTrait for MyStruct {
1919+
type X = u32;
1920+
}
1921+
1922+
fn main() {
1923+
let foo: <MyStruct as MyTrait>::X;
1924+
}
1925+
```
1926+
1927+
This syntax specifies that we want the X type from MyTrait, as made concrete in
1928+
MyStruct. The reason that we cannot simply use `MyStruct::X` is that MyStruct
1929+
might implement two different traits with identically-named associated types.
1930+
This syntax allows disambiguation between the two.
1931+
"##,
1932+
1933+
E0225: r##"
1934+
You attempted to use multiple types as bounds for a closure or trait object.
1935+
Rust does not currently support this. A simple example that causes this error:
1936+
1937+
```
1938+
fn main() {
1939+
let _: Box<std::io::Read+std::io::Write>;
1940+
}
1941+
```
1942+
1943+
Builtin traits are an exception to this rule: it's possible to have bounds of
1944+
one non-builtin type, plus any number of builtin types. For example, the
1945+
following compiles correctly:
1946+
1947+
```
1948+
fn main() {
1949+
let _: Box<std::io::Read+Copy+Sync>;
1950+
}
1951+
```
1952+
"##,
1953+
18981954
E0232: r##"
18991955
The attribute must have a value. Erroneous code example:
19001956
@@ -2233,9 +2289,7 @@ register_diagnostics! {
22332289
E0221, // ambiguous associated type in bounds
22342290
//E0222, // Error code E0045 (variadic function must have C calling
22352291
// convention) duplicate
2236-
E0223, // ambiguous associated type
22372292
E0224, // at least one non-builtin train is required for an object type
2238-
E0225, // only the builtin traits can be used as closure or object bounds
22392293
E0226, // only a single explicit lifetime bound is permitted
22402294
E0227, // ambiguous lifetime bound, explicit lifetime bound required
22412295
E0228, // explicit lifetime bound required

0 commit comments

Comments
 (0)