Skip to content

Commit 42b3596

Browse files
authored
Rollup merge of #65308 - GuillaumeGomez:long-err-explanation-E0574, r=matthewjasper
Add long error explanation for E0574 Part of #61137.
2 parents ff9b99d + 9f392c4 commit 42b3596

12 files changed

+62
-2
lines changed

src/librustc_resolve/error_codes.rs

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

1614+
E0574: r##"
1615+
Something other than a struct, variant or union has been used when one was
1616+
expected.
1617+
1618+
Erroneous code example:
1619+
1620+
```compile_fail,E0574
1621+
mod Mordor {}
1622+
1623+
let sauron = Mordor { x: () }; // error!
1624+
1625+
enum Jak {
1626+
Daxter { i: isize },
1627+
}
1628+
1629+
let eco = Jak::Daxter { i: 1 };
1630+
match eco {
1631+
Jak { i } => {} // error!
1632+
}
1633+
```
1634+
1635+
In all these errors, a type was expected. For example, in the first error,
1636+
we tried to instantiate the `Mordor` module, which is impossible. If you want
1637+
to instantiate a type inside a module, you can do it as follow:
1638+
1639+
```
1640+
mod Mordor {
1641+
pub struct TheRing {
1642+
pub x: usize,
1643+
}
1644+
}
1645+
1646+
let sauron = Mordor::TheRing { x: 1 }; // ok!
1647+
```
1648+
1649+
In the second error, we tried to bind the `Jak` enum directly, which is not
1650+
possible: you can only bind one of its variants. To do so:
1651+
1652+
```
1653+
enum Jak {
1654+
Daxter { i: isize },
1655+
}
1656+
1657+
let eco = Jak::Daxter { i: 1 };
1658+
match eco {
1659+
Jak::Daxter { i } => {} // ok!
1660+
}
1661+
```
1662+
"##,
1663+
16141664
E0603: r##"
16151665
A private item was used outside its scope.
16161666
@@ -1739,7 +1789,6 @@ struct Foo<X = Box<Self>> {
17391789
// E0467, removed
17401790
// E0470, removed
17411791
E0573,
1742-
E0574,
17431792
E0575,
17441793
E0576,
17451794
E0577,

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

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | let p = foo { x: () };
66

77
error: aborting due to previous error
88

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

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

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | Foo { i } => ()
66

77
error: aborting due to previous error
88

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

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

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | let myVar = MyMod { T: 0 };
66

77
error: aborting due to previous error
88

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

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

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | let _ = module { x: 0 };
66

77
error: aborting due to previous error
88

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

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

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | char{ch} => true
66

77
error: aborting due to previous error
88

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

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

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ LL | u32 { x: 1 } => {}
2424

2525
error: aborting due to 4 previous errors
2626

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

src/test/ui/lexical-scopes.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ LL | Foo::f();
1616

1717
error: aborting due to 2 previous errors
1818

19-
For more information about this error, try `rustc --explain E0599`.
19+
Some errors have detailed explanations: E0574, E0599.
20+
For more information about an error, try `rustc --explain E0574`.

src/test/ui/resolve/issue-16058.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ LL | use std::thread::Result;
1414

1515
error: aborting due to previous error
1616

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

src/test/ui/traits/trait-as-struct-constructor.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | TraitNotAStruct{ value: 0 };
66

77
error: aborting due to previous error
88

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

src/test/ui/try-block/try-block-in-edition2015.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ LL | let try_result: Option<_> = try {
2121

2222
error: aborting due to 2 previous errors
2323

24+
For more information about this error, try `rustc --explain E0574`.

src/test/ui/use/issue-18986.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | Trait { x: 42 } => ()
66

77
error: aborting due to previous error
88

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

0 commit comments

Comments
 (0)