Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add long error explanation for E0573 #65234

Merged
merged 2 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 74 additions & 1 deletion src/librustc_resolve/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, just a random late comment from an outsider... Should the // error! commet be removed because this is a corrected example, shouldn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent point! We completely missed it... Do you want to send a PR to fix it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GuillaumeGomez Hi, I just created one! #65620

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.
Expand Down Expand Up @@ -1788,7 +1862,6 @@ struct Foo<X = Box<Self>> {
// E0427, merged into 530
// E0467, removed
// E0470, removed
E0573,
E0575,
E0576,
E0577,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ LL | #![feature(const_generics)]

error: aborting due to previous error

For more information about this error, try `rustc --explain E0573`.
1 change: 1 addition & 0 deletions src/test/ui/enum/enum-variant-type-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-17546.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-18119.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ LL | impl foo {}

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0573`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-30535.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ LL | _: foo::Foo::FooV

error: aborting due to previous error

For more information about this error, try `rustc --explain E0573`.
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-35675.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
2 changes: 1 addition & 1 deletion src/test/ui/privacy/privacy-ns1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
2 changes: 1 addition & 1 deletion src/test/ui/privacy/privacy-ns2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
1 change: 1 addition & 0 deletions src/test/ui/traits/trait-impl-for-module.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
1 change: 1 addition & 0 deletions src/test/ui/type/type-ascription-with-fn-call.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ LL | f();

error: aborting due to previous error

For more information about this error, try `rustc --explain E0573`.
1 change: 1 addition & 0 deletions src/test/ui/variants/variant-used-as-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ LL | impl Ty {}

error: aborting due to 2 previous errors

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