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.
9 #![feature(bind_by_move_pattern_guards)]
12 fn ok_mutation_in_guard(mut q: i32) {
14 // OK, mutation doesn't change which patterns g matches
15 _ if { q = 1; false } => (),
20 fn ok_mutation_in_guard2(mut u: bool) {
21 // OK value of u is unused before modification
32 fn ok_mutation_in_guard4(mut w: (&mut bool,)) {
33 // OK value of u is unused before modification
44 fn ok_indirect_mutation_in_guard(mut p: &bool) {
46 // OK, mutation doesn't change which patterns s matches
55 fn mutation_invalidates_pattern_in_guard(mut q: bool) {
57 // q doesn't match the pattern with the guard by the end of the guard.
66 fn mutation_invalidates_previous_pattern_in_guard(mut r: bool) {
68 // r matches a previous pattern by the end of the guard.
78 fn match_on_borrowed_early_end(mut s: bool) {
80 // OK value of s is unused before modification.
91 fn bad_mutation_in_guard(mut t: bool) {
102 fn bad_mutation_in_guard2(mut x: Option<Option<&i32>>) {
103 // Check that nested patterns are checked.
109 Some(ref mut r) => *r = None, //~ ERROR
114 Some(Some(r)) => println!("{}", r),
118 fn bad_mutation_in_guard3(mut t: bool) {
123 } => (), // What value should `s` have in the arm?
128 fn bad_indirect_mutation_in_guard(mut y: &bool) {
139 fn bad_indirect_mutation_in_guard2(mut z: &bool) {
150 fn bad_indirect_mutation_in_guard3(mut a: &bool) {
151 // Same as bad_indirect_mutation_in_guard2, but using match ergonomics
162 fn bad_indirect_mutation_in_guard4(mut b: &bool) {