]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/diagnostics.rs
Better messages for errors from Shallow borrows
[rust.git] / src / librustc_mir / diagnostics.rs
index 24197c9e4b88f6c0d844677471974466c75645db..0c31e5c4da8ac605ca65eb25d1512253f39a2ec7 100644 (file)
@@ -1991,6 +1991,26 @@ fn main() {
 ```
 "##,
 
+E0510: r##"
+Cannot mutate place in this match guard.
+
+When matching on a variable it cannot be mutated in the match guards, as this
+could cause the match to be non-exhaustive:
+
+```compile_fail,E0510
+#![feature(nll, bind_by_move_pattern_guards)]
+let mut x = Some(0);
+match x {
+    None => (),
+    Some(v) if { x = None; false } => (),
+    Some(_) => (), // No longer matches
+}
+```
+
+Here executing `x = None` would modify the value being matched and require us
+to go "back in time" to the `None` arm.
+"##,
+
 E0579: r##"
 When matching against an exclusive range, the compiler verifies that the range
 is non-empty. Exclusive range patterns include the start point but not the end