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