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 #![feature(if_let_guard)]
10 fn ok_mutation_in_if_guard(mut q: i32) {
12 // OK, mutation doesn't change which patterns g matches
13 _ if { q = 1; false } => (),
18 fn ok_mutation_in_if_let_guard(mut q: i32) {
20 // OK, mutation doesn't change which patterns g matches
21 _ if let Some(()) = { q = 1; None } => (),
26 fn ok_mutation_in_if_guard2(mut u: bool) {
27 // OK value of u is unused before modification
38 fn ok_mutation_in_if_let_guard2(mut u: bool) {
39 // OK value of u is unused before modification
50 fn ok_mutation_in_if_guard4(mut w: (&mut bool,)) {
51 // OK value of u is unused before modification
62 fn ok_mutation_in_if_let_guard4(mut w: (&mut bool,)) {
63 // OK value of u is unused before modification
74 fn ok_indirect_mutation_in_if_guard(mut p: &bool) {
76 // OK, mutation doesn't change which patterns s matches
85 fn ok_indirect_mutation_in_if_let_guard(mut p: &bool) {
87 // OK, mutation doesn't change which patterns s matches
96 fn mutation_invalidates_pattern_in_if_guard(mut q: bool) {
98 // q doesn't match the pattern with the guard by the end of the guard.
107 fn mutation_invalidates_pattern_in_if_let_guard(mut q: bool) {
109 // q doesn't match the pattern with the guard by the end of the guard.
110 false if let Some(()) = {
118 fn mutation_invalidates_previous_pattern_in_if_guard(mut r: bool) {
120 // r matches a previous pattern by the end of the guard.
130 fn mutation_invalidates_previous_pattern_in_if_let_guard(mut r: bool) {
132 // r matches a previous pattern by the end of the guard.
134 _ if let Some(()) = {
142 fn match_on_borrowed_early_end_if_guard(mut s: bool) {
144 // OK value of s is unused before modification.
155 fn match_on_borrowed_early_end_if_let_guard(mut s: bool) {
157 // OK value of s is unused before modification.
159 _ if let Some(()) = {
168 fn bad_mutation_in_if_guard(mut t: bool) {
179 fn bad_mutation_in_if_let_guard(mut t: bool) {
182 false if let Some(()) = {
190 fn bad_mutation_in_if_guard2(mut x: Option<Option<&i32>>) {
191 // Check that nested patterns are checked.
197 Some(ref mut r) => *r = None, //~ ERROR
202 Some(Some(r)) => println!("{}", r),
206 fn bad_mutation_in_if_let_guard2(mut x: Option<Option<&i32>>) {
207 // Check that nested patterns are checked.
211 _ if let Some(()) = {
213 Some(ref mut r) => *r = None, //~ ERROR
218 Some(Some(r)) => println!("{}", r),
222 fn bad_mutation_in_if_guard3(mut t: bool) {
227 } => (), // What value should `s` have in the arm?
232 fn bad_mutation_in_if_let_guard3(mut t: bool) {
234 s if let Some(()) = {
237 } => (), // What value should `s` have in the arm?
242 fn bad_indirect_mutation_in_if_guard(mut y: &bool) {
253 fn bad_indirect_mutation_in_if_let_guard(mut y: &bool) {
256 false if let Some(()) = {
264 fn bad_indirect_mutation_in_if_guard2(mut z: &bool) {
275 fn bad_indirect_mutation_in_if_let_guard2(mut z: &bool) {
278 &false if let Some(()) = {
286 fn bad_indirect_mutation_in_if_guard3(mut a: &bool) {
287 // Same as bad_indirect_mutation_in_if_guard2, but using match ergonomics
298 fn bad_indirect_mutation_in_if_let_guard3(mut a: &bool) {
299 // Same as bad_indirect_mutation_in_if_guard2, but using match ergonomics
302 false if let Some(()) = {
310 fn bad_indirect_mutation_in_if_guard4(mut b: &bool) {
321 fn bad_indirect_mutation_in_if_let_guard4(mut b: &bool) {
324 &_ if let Some(()) = {