Skip to content

Commit 7e49800

Browse files
committed
Auto merge of #65234 - GuillaumeGomez:long-err-explanation-E0573, r=kinnison
Add long error explanation for E0573 Part of #61137.
2 parents c8fa82c + 7d357fb commit 7e49800

13 files changed

+87
-5
lines changed

src/librustc_resolve/error_codes.rs

+74-1
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,80 @@ fn print_on_failure(state: &State) {
16111611
```
16121612
"##,
16131613

1614+
E0573: r##"
1615+
Something other than a type has been used when one was expected.
1616+
1617+
Erroneous code examples:
1618+
1619+
```compile_fail,E0573
1620+
enum Dragon {
1621+
Born,
1622+
}
1623+
1624+
fn oblivion() -> Dragon::Born { // error!
1625+
Dragon::Born
1626+
}
1627+
1628+
const HOBBIT: u32 = 2;
1629+
impl HOBBIT {} // error!
1630+
1631+
enum Wizard {
1632+
Gandalf,
1633+
Saruman,
1634+
}
1635+
1636+
trait Isengard {
1637+
fn wizard(_: Wizard::Saruman); // error!
1638+
}
1639+
```
1640+
1641+
In all these errors, a type was expected. For example, in the first error, if
1642+
we want to return the `Born` variant from the `Dragon` enum, we must set the
1643+
function to return the enum and not its variant:
1644+
1645+
```
1646+
enum Dragon {
1647+
Born,
1648+
}
1649+
1650+
fn oblivion() -> Dragon { // ok!
1651+
Dragon::Born
1652+
}
1653+
```
1654+
1655+
In the second error, you can't implement something on an item, only on types.
1656+
We would need to create a new type if we wanted to do something similar:
1657+
1658+
```
1659+
struct Hobbit(u32); // we create a new type
1660+
1661+
const HOBBIT: Hobbit = Hobbit(2);
1662+
impl Hobbit {} // ok!
1663+
```
1664+
1665+
In the third case, we tried to only expect one variant of the `Wizard` enum,
1666+
which is not possible. To make this work, we need to using pattern matching
1667+
over the `Wizard` enum:
1668+
1669+
```
1670+
enum Wizard {
1671+
Gandalf,
1672+
Saruman,
1673+
}
1674+
1675+
trait Isengard {
1676+
fn wizard(w: Wizard) { // error!
1677+
match w {
1678+
Wizard::Saruman => {
1679+
// do something
1680+
}
1681+
_ => {} // ignore everything else
1682+
}
1683+
}
1684+
}
1685+
```
1686+
"##,
1687+
16141688
E0574: r##"
16151689
Something other than a struct, variant or union has been used when one was
16161690
expected.
@@ -1788,7 +1862,6 @@ struct Foo<X = Box<Self>> {
17881862
// E0427, merged into 530
17891863
// E0467, removed
17901864
// E0470, removed
1791-
E0573,
17921865
E0575,
17931866
E0576,
17941867
E0577,

src/test/ui/const-generics/struct-with-invalid-const-param.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ LL | #![feature(const_generics)]
1414

1515
error: aborting due to previous error
1616

17+
For more information about this error, try `rustc --explain E0573`.

src/test/ui/enum/enum-variant-type-2.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ LL | fn foo(x: Foo::Bar) {}
99

1010
error: aborting due to previous error
1111

12+
For more information about this error, try `rustc --explain E0573`.

src/test/ui/issues/issue-17546.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ LL | fn newer() -> Result<foo::MyEnum, String> {
6262

6363
error: aborting due to 4 previous errors
6464

65+
For more information about this error, try `rustc --explain E0573`.

src/test/ui/issues/issue-18119.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ LL | impl foo {}
1818

1919
error: aborting due to 3 previous errors
2020

21+
For more information about this error, try `rustc --explain E0573`.

src/test/ui/issues/issue-30535.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ LL | _: foo::Foo::FooV
99

1010
error: aborting due to previous error
1111

12+
For more information about this error, try `rustc --explain E0573`.

src/test/ui/issues/issue-35675.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ LL | fn qux() -> Some {
6767

6868
error: aborting due to 7 previous errors
6969

70-
Some errors have detailed explanations: E0412, E0425.
70+
Some errors have detailed explanations: E0412, E0425, E0573.
7171
For more information about an error, try `rustc --explain E0412`.

src/test/ui/privacy/privacy-ns1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ LL | use foo3::Bar;
7272

7373
error: aborting due to 4 previous errors
7474

75-
Some errors have detailed explanations: E0412, E0423, E0425.
75+
Some errors have detailed explanations: E0412, E0423, E0425, E0573.
7676
For more information about an error, try `rustc --explain E0412`.

src/test/ui/privacy/privacy-ns2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ LL | use foo3::{Bar,Baz};
8282

8383
error: aborting due to 7 previous errors
8484

85-
Some errors have detailed explanations: E0423, E0603.
85+
Some errors have detailed explanations: E0423, E0573, E0603.
8686
For more information about an error, try `rustc --explain E0423`.

src/test/ui/tool-attributes/tool-attributes-misplaced-1.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ LL | rustfmt::skip;
4242

4343
error: aborting due to 7 previous errors
4444

45-
For more information about this error, try `rustc --explain E0423`.
45+
Some errors have detailed explanations: E0423, E0573.
46+
For more information about an error, try `rustc --explain E0423`.

src/test/ui/traits/trait-impl-for-module.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | impl A for a {
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0573`.

src/test/ui/type/type-ascription-with-fn-call.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ LL | f();
1111

1212
error: aborting due to previous error
1313

14+
For more information about this error, try `rustc --explain E0573`.

src/test/ui/variants/variant-used-as-type.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ LL | impl Ty {}
2424

2525
error: aborting due to 2 previous errors
2626

27+
For more information about this error, try `rustc --explain E0573`.

0 commit comments

Comments
 (0)