2019-11-11 04:39:52 -06:00
|
|
|
#![feature(bindings_after_at)]
|
2019-12-14 20:50:55 -06:00
|
|
|
#![feature(slice_patterns)]
|
2019-11-11 04:39:52 -06:00
|
|
|
|
|
|
|
enum Option<T> {
|
|
|
|
None,
|
|
|
|
Some(T),
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
match &mut Some(1) {
|
|
|
|
ref mut z @ &mut Some(ref a) => {
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `z` as immutable because it is also borrowed as mutable
|
|
|
|
//~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
|
2019-11-11 04:39:52 -06:00
|
|
|
**z = None;
|
|
|
|
println!("{}", *a);
|
|
|
|
}
|
|
|
|
_ => ()
|
|
|
|
}
|
|
|
|
|
|
|
|
struct U;
|
|
|
|
|
2019-12-14 17:50:44 -06:00
|
|
|
// Prevent promotion:
|
|
|
|
fn u() -> U { U }
|
|
|
|
|
2019-12-14 20:50:55 -06:00
|
|
|
fn f1(ref a @ ref mut b: U) {}
|
|
|
|
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
|
|
|
|
fn f2(ref mut a @ ref b: U) {}
|
|
|
|
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
|
|
|
|
fn f3(ref a @ [ref b, ref mut mid @ .., ref c]: [U; 4]) {}
|
|
|
|
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
|
|
|
|
|
|
|
|
let ref mut a @ (ref b @ ref mut c) = u(); // sub-in-sub
|
|
|
|
//~^ ERROR cannot borrow `a` as mutable more than once at a time
|
|
|
|
//~| ERROR cannot borrow `b` as mutable because it is also borrowed as immutable
|
|
|
|
|
2019-12-14 17:32:20 -06:00
|
|
|
let ref a @ ref mut b = U;
|
|
|
|
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
|
|
|
|
let ref mut a @ ref b = U;
|
|
|
|
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
|
|
|
|
let ref a @ (ref mut b, ref mut c) = (U, U);
|
|
|
|
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
|
|
|
|
let ref mut a @ (ref b, ref c) = (U, U);
|
|
|
|
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
|
2019-11-11 04:39:52 -06:00
|
|
|
|
2019-12-14 17:50:44 -06:00
|
|
|
let ref mut a @ ref b = u();
|
|
|
|
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
|
|
|
|
//~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
|
|
|
|
*a = u();
|
|
|
|
drop(b);
|
|
|
|
let ref a @ ref mut b = u();
|
|
|
|
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
|
|
|
|
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
|
|
|
|
*b = u();
|
|
|
|
drop(a);
|
|
|
|
|
2019-11-11 04:39:52 -06:00
|
|
|
let ref mut a @ ref b = U;
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
|
|
|
|
*a = U;
|
|
|
|
drop(b);
|
2019-11-11 04:39:52 -06:00
|
|
|
let ref a @ ref mut b = U;
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
|
2019-11-11 04:39:52 -06:00
|
|
|
*b = U;
|
|
|
|
drop(a);
|
|
|
|
|
|
|
|
match Ok(U) {
|
|
|
|
ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) => {
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
|
|
|
|
//~| ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
|
|
|
|
*a = Err(U);
|
2019-11-11 04:39:52 -06:00
|
|
|
drop(b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
match Ok(U) {
|
|
|
|
ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
|
|
|
|
//~| ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
|
|
|
|
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
|
2019-11-11 04:39:52 -06:00
|
|
|
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
|
|
|
|
*b = U;
|
|
|
|
drop(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
match Ok(U) {
|
|
|
|
ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false } => {}
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
|
|
|
|
//~| ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
|
|
|
|
//~| ERROR cannot assign to `*b`, as it is immutable for the pattern guard
|
2019-11-11 04:39:52 -06:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
match Ok(U) {
|
|
|
|
ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { *a = Err(U); false } => {}
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
|
|
|
|
//~| ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
|
|
|
|
//~| ERROR cannot assign to `*a`, as it is immutable for the pattern guard
|
2019-11-11 04:39:52 -06:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
match Ok(U) {
|
|
|
|
ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false } => {}
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
|
|
|
|
//~| ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
|
|
|
|
//~| ERROR cannot move out of `b` in pattern guard
|
2019-11-11 04:39:52 -06:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
match Ok(U) {
|
|
|
|
ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false } => {}
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
|
|
|
|
//~| ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
|
|
|
|
//~| ERROR cannot move out of `a` in pattern guard
|
2019-11-11 04:39:52 -06:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
|
|
|
let ref a @ (ref mut b, ref mut c) = (U, U);
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
|
|
|
|
*b = U;
|
2019-11-11 04:39:52 -06:00
|
|
|
*c = U;
|
|
|
|
|
|
|
|
let ref a @ (ref mut b, ref mut c) = (U, U);
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
|
|
|
|
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
|
2019-11-11 04:39:52 -06:00
|
|
|
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
|
|
|
|
*b = U;
|
|
|
|
drop(a);
|
|
|
|
|
|
|
|
let ref a @ (ref mut b, ref mut c) = (U, U);
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
|
|
|
|
*b = U; //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
|
2019-11-11 04:39:52 -06:00
|
|
|
*c = U; //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
|
|
|
|
drop(a);
|
2019-12-14 17:32:20 -06:00
|
|
|
let ref mut a @ (ref b, ref c) = (U, U);
|
|
|
|
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
|
2019-11-11 04:39:52 -06:00
|
|
|
}
|