2019-11-11 04:39:52 -06:00
|
|
|
// Test that `ref mut x @ ref mut y` and varieties of that are not allowed.
|
|
|
|
|
|
|
|
#![feature(bindings_after_at)]
|
|
|
|
//~^ WARN the feature `bindings_after_at` is incomplete and may cause the compiler to crash
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
struct U;
|
|
|
|
|
2019-12-14 17:50:44 -06:00
|
|
|
fn u() -> U { U }
|
|
|
|
|
2019-11-11 04:39:52 -06:00
|
|
|
let ref mut a @ ref mut b = U;
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `a` as mutable more than once at a time
|
|
|
|
//~| ERROR cannot borrow `_` as mutable more than once at a time
|
2019-11-11 04:39:52 -06:00
|
|
|
drop(a);
|
2019-12-14 17:32:20 -06:00
|
|
|
let ref mut a @ ref mut b = U;
|
|
|
|
//~^ ERROR cannot borrow `a` as mutable more than once at a time
|
2019-11-11 04:39:52 -06:00
|
|
|
drop(b);
|
2019-12-14 17:32:20 -06:00
|
|
|
let ref mut a @ ref mut b = U;
|
|
|
|
//~^ ERROR cannot borrow `a` as mutable more than once at a time
|
2019-11-11 04:39:52 -06:00
|
|
|
|
|
|
|
let ref mut a @ ref mut b = U;
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `a` as mutable more than once at a time
|
|
|
|
//~| ERROR cannot borrow `_` as mutable more than once at a time
|
2019-11-11 04:39:52 -06:00
|
|
|
*a = U;
|
2019-12-14 17:32:20 -06:00
|
|
|
let ref mut a @ ref mut b = U;
|
|
|
|
//~^ ERROR cannot borrow `a` as mutable more than once at a time
|
2019-11-11 04:39:52 -06:00
|
|
|
*b = U;
|
|
|
|
|
2019-12-14 17:32:20 -06:00
|
|
|
let ref mut a @ (
|
|
|
|
//~^ ERROR cannot borrow `a` as mutable more than once at a time
|
|
|
|
ref mut b,
|
|
|
|
[
|
|
|
|
ref mut c,
|
|
|
|
ref mut d,
|
|
|
|
ref e,
|
|
|
|
]
|
|
|
|
) = (U, [U, U, U]);
|
2019-11-11 04:39:52 -06:00
|
|
|
|
2019-12-14 17:50:44 -06:00
|
|
|
let ref mut a @ (
|
|
|
|
//~^ ERROR cannot borrow `a` as mutable more than once at a time
|
|
|
|
ref mut b,
|
|
|
|
[
|
|
|
|
ref mut c,
|
|
|
|
ref mut d,
|
|
|
|
ref e,
|
|
|
|
]
|
|
|
|
) = (u(), [u(), u(), u()]);
|
|
|
|
|
2019-11-11 04:39:52 -06:00
|
|
|
let a @ (ref mut b, ref mut c) = (U, U);
|
|
|
|
//~^ ERROR cannot bind by-move with sub-bindings
|
|
|
|
//~| ERROR borrow of moved value
|
|
|
|
let mut val = (U, [U, U]);
|
|
|
|
let a @ (b, [c, d]) = &mut val; // Same as ^--
|
|
|
|
//~^ ERROR cannot bind by-move with sub-bindings
|
|
|
|
//~| ERROR borrow of moved value
|
|
|
|
|
|
|
|
let a @ &mut ref mut b = &mut U;
|
|
|
|
//~^ ERROR cannot bind by-move with sub-bindings
|
|
|
|
//~| ERROR borrow of moved value
|
|
|
|
let a @ &mut (ref mut b, ref mut c) = &mut (U, U);
|
|
|
|
//~^ ERROR cannot bind by-move with sub-bindings
|
|
|
|
//~| ERROR borrow of moved value
|
|
|
|
|
|
|
|
match Ok(U) {
|
|
|
|
ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `a` as mutable more than once at a time
|
|
|
|
//~| ERROR cannot borrow `a` as mutable more than once at a time
|
2019-11-11 04:39:52 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
match Ok(U) {
|
|
|
|
ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `a` as mutable more than once at a time
|
|
|
|
//~| ERROR cannot borrow `a` as mutable more than once at a time
|
2019-11-11 04:39:52 -06:00
|
|
|
*b = U;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
match Ok(U) {
|
|
|
|
ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `a` as mutable more than once at a time
|
|
|
|
//~| ERROR cannot borrow `a` as mutable more than once at a time
|
|
|
|
//~| ERROR cannot borrow `_` as mutable more than once at a time
|
2019-11-11 04:39:52 -06:00
|
|
|
//~| ERROR cannot borrow `_` as mutable more than once at a time
|
|
|
|
*a = Err(U);
|
|
|
|
|
|
|
|
// FIXME: The binding name `_` used above makes for problematic diagnostics.
|
|
|
|
// Resolve that somehow...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
match Ok(U) {
|
|
|
|
ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
|
2019-12-14 17:32:20 -06:00
|
|
|
//~^ ERROR cannot borrow `a` as mutable more than once at a time
|
|
|
|
//~| ERROR cannot borrow `a` as mutable more than once at a time
|
|
|
|
//~| ERROR cannot borrow `_` as mutable more than once at a time
|
2019-11-11 04:39:52 -06:00
|
|
|
//~| ERROR cannot borrow `_` as mutable more than once at a time
|
|
|
|
drop(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|