File tree Expand file tree Collapse file tree 1 file changed +20
-7
lines changed
src/librustc_error_codes/error_codes Expand file tree Collapse file tree 1 file changed +20
-7
lines changed Original file line number Diff line number Diff line change 1- Cannot mutate place in this match guard.
1+ The matched value was assigned in a match guard.
22
3- When matching on a variable it cannot be mutated in the match guards, as this
4- could cause the match to be non-exhaustive:
3+ Erroneous code example:
54
65``` compile_fail,E0510
76let mut x = Some(0);
87match x {
9- None => (),
10- Some(_) if { x = None; false } => (),
11- Some(v ) => (), // No longer matches
8+ None => {}
9+ Some(_) if { x = None; false } => {} // error!
10+ Some(_ ) => {}
1211}
1312```
1413
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+
1517Here executing ` x = None ` would modify the value being matched and require us
16- to go "back in time" to the ` None ` arm.
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+ ```
You can’t perform that action at this time.
0 commit comments