2019-11-11 04:39:52 -06:00
|
|
|
// Test that `ref mut x @ ref mut y` and varieties of that are not allowed.
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
struct U;
|
|
|
|
|
2019-12-14 17:50:44 -06:00
|
|
|
fn u() -> U { U }
|
|
|
|
|
2019-12-14 20:50:55 -06:00
|
|
|
fn f1(ref mut a @ ref mut b: U) {}
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as mutable more than once at a time
|
2019-12-14 20:50:55 -06:00
|
|
|
fn f2(ref mut a @ ref mut b: U) {}
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as mutable more than once at a time
|
2019-12-14 20:50:55 -06:00
|
|
|
fn f3(
|
|
|
|
ref mut a @ [
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as mutable more than once at a time
|
2019-12-14 20:50:55 -06:00
|
|
|
[ref b @ .., _],
|
|
|
|
[_, ref mut mid @ ..],
|
|
|
|
..,
|
|
|
|
[..],
|
|
|
|
] : [[U; 4]; 5]
|
|
|
|
) {}
|
2020-01-18 19:47:01 -06:00
|
|
|
fn f4_also_moved(ref mut a @ ref mut b @ c: U) {}
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as mutable more than once at a time
|
|
|
|
//~| ERROR cannot move out of value because it is borrowed
|
2020-11-01 12:35:55 -06:00
|
|
|
//~| ERROR borrow of moved value
|
2019-12-14 20:50:55 -06:00
|
|
|
|
2019-11-11 04:39:52 -06:00
|
|
|
let ref mut a @ ref mut b = U;
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value 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;
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as mutable more than once at a time
|
2020-11-01 12:35:55 -06:00
|
|
|
//~| ERROR cannot borrow value 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;
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as mutable more than once at a time
|
2019-11-11 04:39:52 -06:00
|
|
|
|
|
|
|
let ref mut a @ ref mut b = U;
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value 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;
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as mutable more than once at a time
|
2020-11-01 12:35:55 -06:00
|
|
|
//~| ERROR cannot borrow value 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 @ (
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as mutable more than once at a time
|
2019-12-14 17:32:20 -06:00
|
|
|
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 @ (
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as mutable more than once at a time
|
2019-12-14 17:50:44 -06:00
|
|
|
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);
|
2020-01-18 19:47:01 -06:00
|
|
|
//~^ ERROR borrow of moved value
|
2019-11-11 04:39:52 -06:00
|
|
|
let mut val = (U, [U, U]);
|
|
|
|
let a @ (b, [c, d]) = &mut val; // Same as ^--
|
2020-01-18 19:47:01 -06:00
|
|
|
//~^ ERROR borrow of moved value
|
2019-11-11 04:39:52 -06:00
|
|
|
|
|
|
|
let a @ &mut ref mut b = &mut U;
|
2020-01-18 19:47:01 -06:00
|
|
|
//~^ ERROR borrow of moved value
|
2019-11-11 04:39:52 -06:00
|
|
|
let a @ &mut (ref mut b, ref mut c) = &mut (U, U);
|
2020-01-18 19:47:01 -06:00
|
|
|
//~^ ERROR borrow of moved value
|
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) => {
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as mutable more than once at a time
|
|
|
|
//~| ERROR cannot borrow value 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) => {
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as mutable more than once at a time
|
|
|
|
//~| ERROR cannot borrow value 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) => {
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as mutable more than once at a time
|
|
|
|
//~| ERROR cannot borrow value as mutable more than once at a time
|
2020-11-03 00:45:41 -06:00
|
|
|
//~| ERROR cannot borrow value as mutable more than once at a time
|
|
|
|
//~| ERROR cannot borrow value as mutable more than once at a time
|
2019-11-11 04:39:52 -06:00
|
|
|
*a = Err(U);
|
|
|
|
|
2020-03-25 05:17:06 -05:00
|
|
|
// FIXME: The binding name value used above makes for problematic diagnostics.
|
2019-11-11 04:39:52 -06:00
|
|
|
// Resolve that somehow...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
match Ok(U) {
|
|
|
|
ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as mutable more than once at a time
|
|
|
|
//~| ERROR cannot borrow value as mutable more than once at a time
|
2020-11-03 00:45:41 -06:00
|
|
|
//~| ERROR cannot borrow value as mutable more than once at a time
|
|
|
|
//~| ERROR cannot borrow value as mutable more than once at a time
|
2019-11-11 04:39:52 -06:00
|
|
|
drop(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|