Skip to content

Commit b8719aa

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 dbba505 + 21d9258 commit b8719aa

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/librustc_resolve/error_codes.rs

+53-1
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,59 @@ match eco {
17351735
```
17361736
"##,
17371737

1738+
E0575: r##"
1739+
Something other than a type or an associated type was given.
1740+
1741+
Erroneous code example:
1742+
1743+
```compile_fail,E0575
1744+
enum Rick { Morty }
1745+
1746+
let _: <u8 as Rick>::Morty; // error!
1747+
1748+
trait Age {
1749+
type Empire;
1750+
fn Mythology() {}
1751+
}
1752+
1753+
impl Age for u8 {
1754+
type Empire = u16;
1755+
}
1756+
1757+
let _: <u8 as Age>::Mythology; // error!
1758+
```
1759+
1760+
In both cases, we're declaring a variable (called `_`) and we're giving it a
1761+
type. However, `<u8 as Rick>::Morty` and `<u8 as Age>::Mythology` aren't types,
1762+
therefore the compiler throws an error.
1763+
1764+
`<u8 as Rick>::Morty` is an enum variant, you cannot use a variant as a type,
1765+
you have to use the enum directly:
1766+
1767+
```
1768+
enum Rick { Morty }
1769+
1770+
let _: Rick; // ok!
1771+
```
1772+
1773+
`<u8 as Age>::Mythology` is a trait method, which is definitely not a type.
1774+
However, the `Age` trait provides an associated type `Empire` which can be
1775+
used as a type:
1776+
1777+
```
1778+
trait Age {
1779+
type Empire;
1780+
fn Mythology() {}
1781+
}
1782+
1783+
impl Age for u8 {
1784+
type Empire = u16;
1785+
}
1786+
1787+
let _: <u8 as Age>::Empire; // ok!
1788+
```
1789+
"##,
1790+
17381791
E0603: r##"
17391792
A private item was used outside its scope.
17401793
@@ -1862,7 +1915,6 @@ struct Foo<X = Box<Self>> {
18621915
// E0427, merged into 530
18631916
// E0467, removed
18641917
// E0470, removed
1865-
E0575,
18661918
E0576,
18671919
E0577,
18681920
E0578,

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

+1-1
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)