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