Skip to content

Commit 28aa2d9

Browse files
authored
Rollup merge of rust-lang#65334 - GuillaumeGomez:long-err-explanation-E0575, r=kinnison
Add long error explanation for E0575 Part of rust-lang#61137.
2 parents c03e516 + 367cda4 commit 28aa2d9

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/librustc_resolve/error_codes.rs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,59 @@ match eco {
16611661
```
16621662
"##,
16631663

1664+
E0575: r##"
1665+
Something other than a type or an associated type was given.
1666+
1667+
Erroneous code example:
1668+
1669+
```compile_fail,E0575
1670+
enum Rick { Morty }
1671+
1672+
let _: <u8 as Rick>::Morty; // error!
1673+
1674+
trait Age {
1675+
type Empire;
1676+
fn Mythology() {}
1677+
}
1678+
1679+
impl Age for u8 {
1680+
type Empire = u16;
1681+
}
1682+
1683+
let _: <u8 as Age>::Mythology; // error!
1684+
```
1685+
1686+
In both cases, we're declaring a variable (called `_`) and we're giving it a
1687+
type. However, `<u8 as Rick>::Morty` and `<u8 as Age>::Mythology` aren't types,
1688+
therefore the compiler throws an error.
1689+
1690+
`<u8 as Rick>::Morty` is an enum variant, you cannot use a variant as a type,
1691+
you have to use the enum directly:
1692+
1693+
```
1694+
enum Rick { Morty }
1695+
1696+
let _: Rick; // ok!
1697+
```
1698+
1699+
`<u8 as Age>::Mythology` is a trait method, which is definitely not a type.
1700+
However, the `Age` trait provides an associated type `Empire` which can be
1701+
used as a type:
1702+
1703+
```
1704+
trait Age {
1705+
type Empire;
1706+
fn Mythology() {}
1707+
}
1708+
1709+
impl Age for u8 {
1710+
type Empire = u16;
1711+
}
1712+
1713+
let _: <u8 as Age>::Empire; // ok!
1714+
```
1715+
"##,
1716+
16641717
E0603: r##"
16651718
A private item was used outside its scope.
16661719
@@ -1789,7 +1842,6 @@ struct Foo<X = Box<Self>> {
17891842
// E0467, removed
17901843
// E0470, removed
17911844
E0573,
1792-
E0575,
17931845
E0576,
17941846
E0577,
17951847
E0578,

src/test/ui/ufcs/ufcs-partially-resolved.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,5 @@ LL | <u8 as Dr>::X::N;
200200

201201
error: aborting due to 32 previous errors
202202

203-
Some errors have detailed explanations: E0223, E0433, E0599.
203+
Some errors have detailed explanations: E0223, E0433, E0575, E0599.
204204
For more information about an error, try `rustc --explain E0223`.

0 commit comments

Comments
 (0)