@@ -9,7 +9,8 @@ enum Option<T> {
99fn main ( ) {
1010 match & mut Some ( 1 ) {
1111 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
1314 * * z = None ;
1415 println ! ( "{}" , * a) ;
1516 }
@@ -18,30 +19,38 @@ fn main() {
1819
1920 struct U ;
2021
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
2530
26- // FIXME: Seems like we have a soundness hole here.
2731 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 ) ;
3135 let ref a @ ref mut b = U ;
36+ //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
3237 * b = U ;
3338 drop ( a) ;
3439
3540 match Ok ( U ) {
3641 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 ) ;
3845 drop ( b) ;
3946 }
4047 }
4148
4249 match Ok ( U ) {
4350 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
4554 //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
4655 * b = U ;
4756 drop ( a) ;
@@ -50,38 +59,50 @@ fn main() {
5059
5160 match Ok ( U ) {
5261 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
5465 _ => { }
5566 }
5667 match Ok ( U ) {
5768 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
5972 _ => { }
6073 }
6174 match Ok ( U ) {
6275 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
6479 _ => { }
6580 }
6681 match Ok ( U ) {
6782 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
6986 _ => { }
7087 }
7188
7289 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 ;
7492 * c = U ;
7593
7694 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
7897 //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
7998 * b = U ;
8099 drop ( a) ;
81100
82101 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
84104 * c = U ; //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
85105 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
87108}
0 commit comments