]> git.proxmox.com Git - rustc.git/blame - src/librustc_error_codes/error_codes/E0510.md
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0510.md
CommitLineData
ba9703b0 1The matched value was assigned in a match guard.
60c5eb7d 2
ba9703b0 3Erroneous code example:
60c5eb7d
XL
4
5```compile_fail,E0510
6let mut x = Some(0);
7match x {
ba9703b0
XL
8 None => {}
9 Some(_) if { x = None; false } => {} // error!
10 Some(_) => {}
60c5eb7d
XL
11}
12```
13
ba9703b0
XL
14When matching on a variable it cannot be mutated in the match guards, as this
15could cause the match to be non-exhaustive.
16
60c5eb7d 17Here executing `x = None` would modify the value being matched and require us
ba9703b0
XL
18to go "back in time" to the `None` arm. To fix it, change the value in the match
19arm:
20
21```
22let mut x = Some(0);
23match x {
24 None => {}
25 Some(_) => {
26 x = None; // ok!
27 }
28}
29```