1 // Test that a (partially) mutably borrowed place can be matched on, so long as
2 // we don't have to read any values that are mutably borrowed to determine
5 // Test that we don't allow mutating the value being matched on in a way that
6 // changes which patterns it matches, until we have chosen an arm.
8 fn ok_mutation_in_guard(mut q: i32) {
10 // OK, mutation doesn't change which patterns g matches
11 _ if { q = 1; false } => (),
16 fn ok_mutation_in_guard2(mut u: bool) {
17 // OK value of u is unused before modification
28 fn ok_mutation_in_guard4(mut w: (&mut bool,)) {
29 // OK value of u is unused before modification
40 fn ok_indirect_mutation_in_guard(mut p: &bool) {
42 // OK, mutation doesn't change which patterns s matches
51 fn mutation_invalidates_pattern_in_guard(mut q: bool) {
53 // q doesn't match the pattern with the guard by the end of the guard.
62 fn mutation_invalidates_previous_pattern_in_guard(mut r: bool) {
64 // r matches a previous pattern by the end of the guard.
74 fn match_on_borrowed_early_end(mut s: bool) {
76 // OK value of s is unused before modification.
87 fn bad_mutation_in_guard(mut t: bool) {
98 fn bad_mutation_in_guard2(mut x: Option<Option<&i32>>) {
99 // Check that nested patterns are checked.
105 Some(ref mut r) => *r = None, //~ ERROR
110 Some(Some(r)) => println!("{}", r),
114 fn bad_mutation_in_guard3(mut t: bool) {
119 } => (), // What value should `s` have in the arm?
124 fn bad_indirect_mutation_in_guard(mut y: &bool) {
135 fn bad_indirect_mutation_in_guard2(mut z: &bool) {
146 fn bad_indirect_mutation_in_guard3(mut a: &bool) {
147 // Same as bad_indirect_mutation_in_guard2, but using match ergonomics
158 fn bad_indirect_mutation_in_guard4(mut b: &bool) {