]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0533.md
Rollup merge of #93556 - dtolnay:trailingcomma, r=cjgillot
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0533.md
1 An item which isn't a unit struct, a variant, nor a constant has been used as a
2 match pattern.
3
4 Erroneous code example:
5
6 ```compile_fail,E0533
7 struct Tortoise;
8
9 impl Tortoise {
10     fn turtle(&self) -> u32 { 0 }
11 }
12
13 match 0u32 {
14     Tortoise::turtle => {} // Error!
15     _ => {}
16 }
17 if let Tortoise::turtle = 0u32 {} // Same error!
18 ```
19
20 If you want to match against a value returned by a method, you need to bind the
21 value first:
22
23 ```
24 struct Tortoise;
25
26 impl Tortoise {
27     fn turtle(&self) -> u32 { 0 }
28 }
29
30 match 0u32 {
31     x if x == Tortoise.turtle() => {} // Bound into `x` then we compare it!
32     _ => {}
33 }
34 ```