diff --git a/src/librustc_typeck/error_codes.rs b/src/librustc_typeck/error_codes.rs index e11dcfafb8f8b..3a07171b12fb8 100644 --- a/src/librustc_typeck/error_codes.rs +++ b/src/librustc_typeck/error_codes.rs @@ -3610,6 +3610,43 @@ match r { ``` "##, +E0533: r##" +An item which isn't a unit struct, a variant, nor a constant has been used as a +match pattern. + +Erroneous code example: + +```compile_fail,E0533 +struct Tortoise; + +impl Tortoise { + fn turtle(&self) -> u32 { 0 } +} + +match 0u32 { + Tortoise::turtle => {} // Error! + _ => {} +} +if let Tortoise::turtle = 0u32 {} // Same error! +``` + +If you want to match against a value returned by a method, you need to bind the +value first: + +``` +struct Tortoise; + +impl Tortoise { + fn turtle(&self) -> u32 { 0 } +} + +match 0u32 { + x if x == Tortoise.turtle() => {} // Bound into `x` then we compare it! + _ => {} +} +``` +"##, + E0534: r##" The `inline` attribute was malformed. @@ -4935,7 +4972,6 @@ and the pin is required to keep it in the same place in memory. E0377, // the trait `CoerceUnsized` may only be implemented for a coercion // between structures with the same definition // E0558, // replaced with a generic attribute input check - E0533, // `{}` does not name a unit variant, unit struct or a constant // E0563, // cannot determine a type for this `impl Trait` removed in 6383de15 E0564, // only named lifetimes are allowed in `impl Trait`, // but `{}` was found in the type `{}` diff --git a/src/test/ui/methods/method-path-in-pattern.rs b/src/test/ui/methods/method-path-in-pattern.rs index fb1cf7f71e70a..21a91f3f32b24 100644 --- a/src/test/ui/methods/method-path-in-pattern.rs +++ b/src/test/ui/methods/method-path-in-pattern.rs @@ -23,4 +23,10 @@ fn main() { ::trait_bar => {} //~^ ERROR expected unit struct/variant or constant, found method `::trait_bar` } + if let Foo::bar = 0u32 {} + //~^ ERROR expected unit struct/variant or constant, found method `::bar` + if let ::bar = 0u32 {} + //~^ ERROR expected unit struct/variant or constant, found method `::bar` + if let Foo::trait_bar = 0u32 {} + //~^ ERROR expected unit struct/variant or constant, found method `::trait_bar` } diff --git a/src/test/ui/methods/method-path-in-pattern.stderr b/src/test/ui/methods/method-path-in-pattern.stderr index 3f53ad768825b..257fff4c37dc0 100644 --- a/src/test/ui/methods/method-path-in-pattern.stderr +++ b/src/test/ui/methods/method-path-in-pattern.stderr @@ -16,5 +16,24 @@ error[E0533]: expected unit struct/variant or constant, found method `::tra LL | ::trait_bar => {} | ^^^^^^^^^^^^^^^^ -error: aborting due to 3 previous errors +error[E0533]: expected unit struct/variant or constant, found method `::bar` + --> $DIR/method-path-in-pattern.rs:26:12 + | +LL | if let Foo::bar = 0u32 {} + | ^^^^^^^^ + +error[E0533]: expected unit struct/variant or constant, found method `::bar` + --> $DIR/method-path-in-pattern.rs:28:12 + | +LL | if let ::bar = 0u32 {} + | ^^^^^^^^^^ + +error[E0533]: expected unit struct/variant or constant, found method `::trait_bar` + --> $DIR/method-path-in-pattern.rs:30:12 + | +LL | if let Foo::trait_bar = 0u32 {} + | ^^^^^^^^^^^^^^ + +error: aborting due to 6 previous errors +For more information about this error, try `rustc --explain E0533`. diff --git a/src/test/ui/qualified/qualified-path-params.stderr b/src/test/ui/qualified/qualified-path-params.stderr index b8d3b744e837c..3e8fcdc7ca3e2 100644 --- a/src/test/ui/qualified/qualified-path-params.stderr +++ b/src/test/ui/qualified/qualified-path-params.stderr @@ -15,4 +15,5 @@ LL | 0 ..= ::A::f:: => {} error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0029`. +Some errors have detailed explanations: E0029, E0533. +For more information about an error, try `rustc --explain E0029`. diff --git a/src/test/ui/type-alias-enum-variants/incorrect-variant-form-through-Self-issue-58006.stderr b/src/test/ui/type-alias-enum-variants/incorrect-variant-form-through-Self-issue-58006.stderr index 128a85e15634c..357b33de51b84 100644 --- a/src/test/ui/type-alias-enum-variants/incorrect-variant-form-through-Self-issue-58006.stderr +++ b/src/test/ui/type-alias-enum-variants/incorrect-variant-form-through-Self-issue-58006.stderr @@ -6,3 +6,4 @@ LL | Self::A => (), error: aborting due to previous error +For more information about this error, try `rustc --explain E0533`. diff --git a/src/test/ui/type-alias-enum-variants/incorrect-variant-form-through-alias-caught.stderr b/src/test/ui/type-alias-enum-variants/incorrect-variant-form-through-alias-caught.stderr index c1ea816b7facf..c6528e417d8ae 100644 --- a/src/test/ui/type-alias-enum-variants/incorrect-variant-form-through-alias-caught.stderr +++ b/src/test/ui/type-alias-enum-variants/incorrect-variant-form-through-alias-caught.stderr @@ -39,5 +39,5 @@ LL | let Alias::Unit() = panic!(); error: aborting due to 5 previous errors -Some errors have detailed explanations: E0164, E0618. +Some errors have detailed explanations: E0164, E0533, E0618. For more information about an error, try `rustc --explain E0164`.