From e5d566c08024db5777af42aa2ffc385a58782afe Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 9 Oct 2019 14:19:39 +0200 Subject: [PATCH 1/2] Add long error explanation for E0573 --- src/librustc_resolve/error_codes.rs | 75 ++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/src/librustc_resolve/error_codes.rs b/src/librustc_resolve/error_codes.rs index 1e65cbada069d..ab3d95dd8edfe 100644 --- a/src/librustc_resolve/error_codes.rs +++ b/src/librustc_resolve/error_codes.rs @@ -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> { // E0427, merged into 530 // E0467, removed // E0470, removed - E0573, E0575, E0576, E0577, From 7d357fbffd7338957fe993b8dc28b91ca5c422b4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 9 Oct 2019 14:19:48 +0200 Subject: [PATCH 2/2] update ui tests --- .../ui/const-generics/struct-with-invalid-const-param.stderr | 1 + src/test/ui/enum/enum-variant-type-2.stderr | 1 + src/test/ui/issues/issue-17546.stderr | 1 + src/test/ui/issues/issue-18119.stderr | 1 + src/test/ui/issues/issue-30535.stderr | 1 + src/test/ui/issues/issue-35675.stderr | 2 +- src/test/ui/privacy/privacy-ns1.stderr | 2 +- src/test/ui/privacy/privacy-ns2.stderr | 2 +- src/test/ui/tool-attributes/tool-attributes-misplaced-1.stderr | 3 ++- src/test/ui/traits/trait-impl-for-module.stderr | 1 + src/test/ui/type/type-ascription-with-fn-call.stderr | 1 + src/test/ui/variants/variant-used-as-type.stderr | 1 + 12 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/test/ui/const-generics/struct-with-invalid-const-param.stderr b/src/test/ui/const-generics/struct-with-invalid-const-param.stderr index dfa2557e9f6f8..b3aa35e079aec 100644 --- a/src/test/ui/const-generics/struct-with-invalid-const-param.stderr +++ b/src/test/ui/const-generics/struct-with-invalid-const-param.stderr @@ -14,3 +14,4 @@ LL | #![feature(const_generics)] error: aborting due to previous error +For more information about this error, try `rustc --explain E0573`. diff --git a/src/test/ui/enum/enum-variant-type-2.stderr b/src/test/ui/enum/enum-variant-type-2.stderr index 65c45d9bad0dc..7e8453c61f62b 100644 --- a/src/test/ui/enum/enum-variant-type-2.stderr +++ b/src/test/ui/enum/enum-variant-type-2.stderr @@ -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`. diff --git a/src/test/ui/issues/issue-17546.stderr b/src/test/ui/issues/issue-17546.stderr index 1f71e159f182b..4a0fb186e49f6 100644 --- a/src/test/ui/issues/issue-17546.stderr +++ b/src/test/ui/issues/issue-17546.stderr @@ -62,3 +62,4 @@ LL | fn newer() -> Result { error: aborting due to 4 previous errors +For more information about this error, try `rustc --explain E0573`. diff --git a/src/test/ui/issues/issue-18119.stderr b/src/test/ui/issues/issue-18119.stderr index 4c5b940190ee6..ddee5a9da7a42 100644 --- a/src/test/ui/issues/issue-18119.stderr +++ b/src/test/ui/issues/issue-18119.stderr @@ -18,3 +18,4 @@ LL | impl foo {} error: aborting due to 3 previous errors +For more information about this error, try `rustc --explain E0573`. diff --git a/src/test/ui/issues/issue-30535.stderr b/src/test/ui/issues/issue-30535.stderr index 5faf0374210d8..e3692934b62ad 100644 --- a/src/test/ui/issues/issue-30535.stderr +++ b/src/test/ui/issues/issue-30535.stderr @@ -9,3 +9,4 @@ LL | _: foo::Foo::FooV error: aborting due to previous error +For more information about this error, try `rustc --explain E0573`. diff --git a/src/test/ui/issues/issue-35675.stderr b/src/test/ui/issues/issue-35675.stderr index 856d6506f2a9f..91814d9496376 100644 --- a/src/test/ui/issues/issue-35675.stderr +++ b/src/test/ui/issues/issue-35675.stderr @@ -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`. diff --git a/src/test/ui/privacy/privacy-ns1.stderr b/src/test/ui/privacy/privacy-ns1.stderr index 09148f9d0e6e1..8ffc12c31cb66 100644 --- a/src/test/ui/privacy/privacy-ns1.stderr +++ b/src/test/ui/privacy/privacy-ns1.stderr @@ -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`. diff --git a/src/test/ui/privacy/privacy-ns2.stderr b/src/test/ui/privacy/privacy-ns2.stderr index 8ea32f36f9e7a..13057a899f3c9 100644 --- a/src/test/ui/privacy/privacy-ns2.stderr +++ b/src/test/ui/privacy/privacy-ns2.stderr @@ -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`. diff --git a/src/test/ui/tool-attributes/tool-attributes-misplaced-1.stderr b/src/test/ui/tool-attributes/tool-attributes-misplaced-1.stderr index 6bef793e0e71b..b831e624cb6ff 100644 --- a/src/test/ui/tool-attributes/tool-attributes-misplaced-1.stderr +++ b/src/test/ui/tool-attributes/tool-attributes-misplaced-1.stderr @@ -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`. diff --git a/src/test/ui/traits/trait-impl-for-module.stderr b/src/test/ui/traits/trait-impl-for-module.stderr index 4a06cd777d49e..c62bcfca94de9 100644 --- a/src/test/ui/traits/trait-impl-for-module.stderr +++ b/src/test/ui/traits/trait-impl-for-module.stderr @@ -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`. diff --git a/src/test/ui/type/type-ascription-with-fn-call.stderr b/src/test/ui/type/type-ascription-with-fn-call.stderr index 624c817e33e32..eeaca5300f9b6 100644 --- a/src/test/ui/type/type-ascription-with-fn-call.stderr +++ b/src/test/ui/type/type-ascription-with-fn-call.stderr @@ -11,3 +11,4 @@ LL | f(); error: aborting due to previous error +For more information about this error, try `rustc --explain E0573`. diff --git a/src/test/ui/variants/variant-used-as-type.stderr b/src/test/ui/variants/variant-used-as-type.stderr index 1138b69ae3bc3..fdfc044d81f6c 100644 --- a/src/test/ui/variants/variant-used-as-type.stderr +++ b/src/test/ui/variants/variant-used-as-type.stderr @@ -24,3 +24,4 @@ LL | impl Ty {} error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0573`.