]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/match-guards-partially-borrow.rs
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(bind_by_move_pattern_guards)]
10 fn ok_mutation_in_guard(mut q
: i32) {
12 // OK, mutation doesn't change which patterns g matches
13 _
if { q = 1; false }
=> (),
18 fn ok_mutation_in_guard2(mut u
: bool
) {
19 // OK value of u is unused before modification
30 fn ok_mutation_in_guard4(mut w
: (&mut bool
,)) {
31 // OK value of u is unused before modification
42 fn ok_indirect_mutation_in_guard(mut p
: &bool
) {
44 // OK, mutation doesn't change which patterns s matches
53 fn mutation_invalidates_pattern_in_guard(mut q
: bool
) {
55 // q doesn't match the pattern with the guard by the end of the guard.
64 fn mutation_invalidates_previous_pattern_in_guard(mut r
: bool
) {
66 // r matches a previous pattern by the end of the guard.
76 fn match_on_borrowed_early_end(mut s
: bool
) {
78 // OK value of s is unused before modification.
89 fn bad_mutation_in_guard(mut t
: bool
) {
100 fn bad_mutation_in_guard2(mut x
: Option
<Option
<&i32>>) {
101 // Check that nested patterns are checked.
107 Some(ref mut r
) => *r
= None
, //~ ERROR
112 Some(Some(r
)) => println
!("{}", r
),
116 fn bad_mutation_in_guard3(mut t
: bool
) {
121 } => (), // What value should `s` have in the arm?
126 fn bad_indirect_mutation_in_guard(mut y
: &bool
) {
137 fn bad_indirect_mutation_in_guard2(mut z
: &bool
) {
148 fn bad_indirect_mutation_in_guard3(mut a
: &bool
) {
149 // Same as bad_indirect_mutation_in_guard2, but using match ergonomics
160 fn bad_indirect_mutation_in_guard4(mut b
: &bool
) {