File tree 1 file changed +20
-7
lines changed
src/librustc_error_codes/error_codes
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.
2
2
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:
5
4
6
5
``` compile_fail,E0510
7
6
let mut x = Some(0);
8
7
match 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(_ ) => {}
12
11
}
13
12
```
14
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
+
15
17
Here 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