Auto merge of #65234 - GuillaumeGomez:long-err-explanation-E0573, r=kinnison
Add long error explanation for E0573 Part of #61137.
This commit is contained in:
commit
7e498005a1
@ -1611,6 +1611,80 @@ fn print_on_failure(state: &State) {
|
||||
```
|
||||
"##,
|
||||
|
||||
E0573: r##"
|
||||
Something other than a type has been used when one was expected.
|
||||
|
||||
Erroneous code examples:
|
||||
|
||||
```compile_fail,E0573
|
||||
enum Dragon {
|
||||
Born,
|
||||
}
|
||||
|
||||
fn oblivion() -> Dragon::Born { // error!
|
||||
Dragon::Born
|
||||
}
|
||||
|
||||
const HOBBIT: u32 = 2;
|
||||
impl HOBBIT {} // error!
|
||||
|
||||
enum Wizard {
|
||||
Gandalf,
|
||||
Saruman,
|
||||
}
|
||||
|
||||
trait Isengard {
|
||||
fn wizard(_: Wizard::Saruman); // error!
|
||||
}
|
||||
```
|
||||
|
||||
In all these errors, a type was expected. For example, in the first error, if
|
||||
we want to return the `Born` variant from the `Dragon` enum, we must set the
|
||||
function to return the enum and not its variant:
|
||||
|
||||
```
|
||||
enum Dragon {
|
||||
Born,
|
||||
}
|
||||
|
||||
fn oblivion() -> Dragon { // ok!
|
||||
Dragon::Born
|
||||
}
|
||||
```
|
||||
|
||||
In the second error, you can't implement something on an item, only on types.
|
||||
We would need to create a new type if we wanted to do something similar:
|
||||
|
||||
```
|
||||
struct Hobbit(u32); // we create a new type
|
||||
|
||||
const HOBBIT: Hobbit = Hobbit(2);
|
||||
impl Hobbit {} // ok!
|
||||
```
|
||||
|
||||
In the third case, we tried to only expect one variant of the `Wizard` enum,
|
||||
which is not possible. To make this work, we need to using pattern matching
|
||||
over the `Wizard` enum:
|
||||
|
||||
```
|
||||
enum Wizard {
|
||||
Gandalf,
|
||||
Saruman,
|
||||
}
|
||||
|
||||
trait Isengard {
|
||||
fn wizard(w: Wizard) { // error!
|
||||
match w {
|
||||
Wizard::Saruman => {
|
||||
// do something
|
||||
}
|
||||
_ => {} // ignore everything else
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
||||
E0574: r##"
|
||||
Something other than a struct, variant or union has been used when one was
|
||||
expected.
|
||||
@ -1788,7 +1862,6 @@ struct Foo<X = Box<Self>> {
|
||||
// E0427, merged into 530
|
||||
// E0467, removed
|
||||
// E0470, removed
|
||||
E0573,
|
||||
E0575,
|
||||
E0576,
|
||||
E0577,
|
||||
|
@ -14,3 +14,4 @@ LL | #![feature(const_generics)]
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0573`.
|
||||
|
@ -9,3 +9,4 @@ LL | fn foo(x: Foo::Bar) {}
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0573`.
|
||||
|
@ -62,3 +62,4 @@ LL | fn newer() -> Result<foo::MyEnum, String> {
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0573`.
|
||||
|
@ -18,3 +18,4 @@ LL | impl foo {}
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0573`.
|
||||
|
@ -9,3 +9,4 @@ LL | _: foo::Foo::FooV
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0573`.
|
||||
|
@ -67,5 +67,5 @@ LL | fn qux() -> Some {
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0412, E0425.
|
||||
Some errors have detailed explanations: E0412, E0425, E0573.
|
||||
For more information about an error, try `rustc --explain E0412`.
|
||||
|
@ -72,5 +72,5 @@ LL | use foo3::Bar;
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0412, E0423, E0425.
|
||||
Some errors have detailed explanations: E0412, E0423, E0425, E0573.
|
||||
For more information about an error, try `rustc --explain E0412`.
|
||||
|
@ -82,5 +82,5 @@ LL | use foo3::{Bar,Baz};
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0423, E0603.
|
||||
Some errors have detailed explanations: E0423, E0573, E0603.
|
||||
For more information about an error, try `rustc --explain E0423`.
|
||||
|
@ -42,4 +42,5 @@ LL | rustfmt::skip;
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0423`.
|
||||
Some errors have detailed explanations: E0423, E0573.
|
||||
For more information about an error, try `rustc --explain E0423`.
|
||||
|
@ -6,3 +6,4 @@ LL | impl A for a {
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0573`.
|
||||
|
@ -11,3 +11,4 @@ LL | f();
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0573`.
|
||||
|
@ -24,3 +24,4 @@ LL | impl Ty {}
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0573`.
|
||||
|
Loading…
x
Reference in New Issue
Block a user