Skip to content

Commit 787ae9c

Browse files
authored
Rollup merge of rust-lang#64735 - GuillaumeGomez:long-err-explanation-E0533, r=Centril
Add long error explanation for E0533 Part of rust-lang#61137
2 parents 66db9e7 + e58e144 commit 787ae9c

6 files changed

+67
-4
lines changed

src/librustc_typeck/error_codes.rs

+37-1
Original file line numberDiff line numberDiff line change
@@ -3610,6 +3610,43 @@ match r {
36103610
```
36113611
"##,
36123612

3613+
E0533: r##"
3614+
An item which isn't a unit struct, a variant, nor a constant has been used as a
3615+
match pattern.
3616+
3617+
Erroneous code example:
3618+
3619+
```compile_fail,E0533
3620+
struct Tortoise;
3621+
3622+
impl Tortoise {
3623+
fn turtle(&self) -> u32 { 0 }
3624+
}
3625+
3626+
match 0u32 {
3627+
Tortoise::turtle => {} // Error!
3628+
_ => {}
3629+
}
3630+
if let Tortoise::turtle = 0u32 {} // Same error!
3631+
```
3632+
3633+
If you want to match against a value returned by a method, you need to bind the
3634+
value first:
3635+
3636+
```
3637+
struct Tortoise;
3638+
3639+
impl Tortoise {
3640+
fn turtle(&self) -> u32 { 0 }
3641+
}
3642+
3643+
match 0u32 {
3644+
x if x == Tortoise.turtle() => {} // Bound into `x` then we compare it!
3645+
_ => {}
3646+
}
3647+
```
3648+
"##,
3649+
36133650
E0534: r##"
36143651
The `inline` attribute was malformed.
36153652
@@ -4935,7 +4972,6 @@ and the pin is required to keep it in the same place in memory.
49354972
E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
49364973
// between structures with the same definition
49374974
// E0558, // replaced with a generic attribute input check
4938-
E0533, // `{}` does not name a unit variant, unit struct or a constant
49394975
// E0563, // cannot determine a type for this `impl Trait` removed in 6383de15
49404976
E0564, // only named lifetimes are allowed in `impl Trait`,
49414977
// but `{}` was found in the type `{}`

src/test/ui/methods/method-path-in-pattern.rs

+6
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ fn main() {
2323
<Foo>::trait_bar => {}
2424
//~^ ERROR expected unit struct/variant or constant, found method `<Foo>::trait_bar`
2525
}
26+
if let Foo::bar = 0u32 {}
27+
//~^ ERROR expected unit struct/variant or constant, found method `<Foo>::bar`
28+
if let <Foo>::bar = 0u32 {}
29+
//~^ ERROR expected unit struct/variant or constant, found method `<Foo>::bar`
30+
if let Foo::trait_bar = 0u32 {}
31+
//~^ ERROR expected unit struct/variant or constant, found method `<Foo>::trait_bar`
2632
}

src/test/ui/methods/method-path-in-pattern.stderr

+20-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,24 @@ error[E0533]: expected unit struct/variant or constant, found method `<Foo>::tra
1616
LL | <Foo>::trait_bar => {}
1717
| ^^^^^^^^^^^^^^^^
1818

19-
error: aborting due to 3 previous errors
19+
error[E0533]: expected unit struct/variant or constant, found method `<Foo>::bar`
20+
--> $DIR/method-path-in-pattern.rs:26:12
21+
|
22+
LL | if let Foo::bar = 0u32 {}
23+
| ^^^^^^^^
24+
25+
error[E0533]: expected unit struct/variant or constant, found method `<Foo>::bar`
26+
--> $DIR/method-path-in-pattern.rs:28:12
27+
|
28+
LL | if let <Foo>::bar = 0u32 {}
29+
| ^^^^^^^^^^
30+
31+
error[E0533]: expected unit struct/variant or constant, found method `<Foo>::trait_bar`
32+
--> $DIR/method-path-in-pattern.rs:30:12
33+
|
34+
LL | if let Foo::trait_bar = 0u32 {}
35+
| ^^^^^^^^^^^^^^
36+
37+
error: aborting due to 6 previous errors
2038

39+
For more information about this error, try `rustc --explain E0533`.

src/test/ui/qualified/qualified-path-params.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ LL | 0 ..= <S as Tr>::A::f::<u8> => {}
1515

1616
error: aborting due to 2 previous errors
1717

18-
For more information about this error, try `rustc --explain E0029`.
18+
Some errors have detailed explanations: E0029, E0533.
19+
For more information about an error, try `rustc --explain E0029`.

src/test/ui/type-alias-enum-variants/incorrect-variant-form-through-Self-issue-58006.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | Self::A => (),
66

77
error: aborting due to previous error
88

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

src/test/ui/type-alias-enum-variants/incorrect-variant-form-through-alias-caught.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ LL | let Alias::Unit() = panic!();
3939

4040
error: aborting due to 5 previous errors
4141

42-
Some errors have detailed explanations: E0164, E0618.
42+
Some errors have detailed explanations: E0164, E0533, E0618.
4343
For more information about an error, try `rustc --explain E0164`.

0 commit comments

Comments
 (0)