@@ -9,7 +9,8 @@ enum Option<T> {
9
9
fn main ( ) {
10
10
match & mut Some ( 1 ) {
11
11
ref mut z @ & mut Some ( ref a) => {
12
- //~^ ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
12
+ //~^ ERROR cannot borrow `z` as immutable because it is also borrowed as mutable
13
+ //~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
13
14
* * z = None ;
14
15
println ! ( "{}" , * a) ;
15
16
}
@@ -18,30 +19,38 @@ fn main() {
18
19
19
20
struct U ;
20
21
21
- let ref a @ ref mut b = U ; // FIXME: This should not compile.
22
- let ref mut a @ ref b = U ; // FIXME: This should not compile.
23
- let ref a @ ( ref mut b, ref mut c) = ( U , U ) ; // FIXME: This should not compile.
24
- let ref mut a @ ( ref b, ref c) = ( U , U ) ; // FIXME: This should not compile.
22
+ let ref a @ ref mut b = U ;
23
+ //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
24
+ let ref mut a @ ref b = U ;
25
+ //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
26
+ let ref a @ ( ref mut b, ref mut c) = ( U , U ) ;
27
+ //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
28
+ let ref mut a @ ( ref b, ref c) = ( U , U ) ;
29
+ //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
25
30
26
- // FIXME: Seems like we have a soundness hole here.
27
31
let ref mut a @ ref b = U ;
28
- * a = U ; // We are mutating...
29
- drop ( b ) ; // ..but at the same time we are holding a live shared borrow.
30
- // FIXME: Inverted; seems like the same issue exists here as well.
32
+ //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
33
+ * a = U ;
34
+ drop ( b ) ;
31
35
let ref a @ ref mut b = U ;
36
+ //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
32
37
* b = U ;
33
38
drop ( a) ;
34
39
35
40
match Ok ( U ) {
36
41
ref mut a @ Ok ( ref b) | ref mut a @ Err ( ref b) => {
37
- * a = Err ( U ) ; // FIXME: ^ should not compile.
42
+ //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
43
+ //~| ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
44
+ * a = Err ( U ) ;
38
45
drop ( b) ;
39
46
}
40
47
}
41
48
42
49
match Ok ( U ) {
43
50
ref a @ Ok ( ref mut b) | ref a @ Err ( ref mut b) => {
44
- //~^ ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
51
+ //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
52
+ //~| ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
53
+ //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
45
54
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
46
55
* b = U ;
47
56
drop ( a) ;
@@ -50,38 +59,50 @@ fn main() {
50
59
51
60
match Ok ( U ) {
52
61
ref a @ Ok ( ref mut b) | ref a @ Err ( ref mut b) if { * b = U ; false } => { }
53
- //~^ ERROR cannot assign to `*b`, as it is immutable for the pattern guard
62
+ //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
63
+ //~| ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
64
+ //~| ERROR cannot assign to `*b`, as it is immutable for the pattern guard
54
65
_ => { }
55
66
}
56
67
match Ok ( U ) {
57
68
ref mut a @ Ok ( ref b) | ref mut a @ Err ( ref b) if { * a = Err ( U ) ; false } => { }
58
- //~^ ERROR cannot assign to `*a`, as it is immutable for the pattern guard
69
+ //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
70
+ //~| ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
71
+ //~| ERROR cannot assign to `*a`, as it is immutable for the pattern guard
59
72
_ => { }
60
73
}
61
74
match Ok ( U ) {
62
75
ref a @ Ok ( ref mut b) | ref a @ Err ( ref mut b) if { drop ( b) ; false } => { }
63
- //~^ ERROR cannot move out of `b` in pattern guard
76
+ //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
77
+ //~| ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
78
+ //~| ERROR cannot move out of `b` in pattern guard
64
79
_ => { }
65
80
}
66
81
match Ok ( U ) {
67
82
ref mut a @ Ok ( ref b) | ref mut a @ Err ( ref b) if { drop ( a) ; false } => { }
68
- //~^ ERROR cannot move out of `a` in pattern guard
83
+ //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
84
+ //~| ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
85
+ //~| ERROR cannot move out of `a` in pattern guard
69
86
_ => { }
70
87
}
71
88
72
89
let ref a @ ( ref mut b, ref mut c) = ( U , U ) ;
73
- * b = U ; // FIXME: ^ should not compile.
90
+ //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
91
+ * b = U ;
74
92
* c = U ;
75
93
76
94
let ref a @ ( ref mut b, ref mut c) = ( U , U ) ;
77
- //~^ ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
95
+ //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
96
+ //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
78
97
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
79
98
* b = U ;
80
99
drop ( a) ;
81
100
82
101
let ref a @ ( ref mut b, ref mut c) = ( U , U ) ;
83
- * b = U ; //~^ ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
102
+ //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
103
+ * b = U ; //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
84
104
* c = U ; //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
85
105
drop ( a) ;
86
- let ref mut a @ ( ref b, ref c) = ( U , U ) ; // FIXME: This should not compile.
106
+ let ref mut a @ ( ref b, ref c) = ( U , U ) ;
107
+ //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
87
108
}
0 commit comments