2019-11-11 04:39:52 -06:00
|
|
|
// Test `@` patterns combined with `box` patterns.
|
|
|
|
|
|
|
|
#![feature(box_patterns)]
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
struct C;
|
|
|
|
|
2020-01-18 19:47:01 -06:00
|
|
|
fn c() -> C {
|
|
|
|
C
|
|
|
|
}
|
2019-12-14 17:50:44 -06:00
|
|
|
|
2019-12-14 20:50:55 -06:00
|
|
|
struct NC;
|
|
|
|
|
2020-01-18 19:47:01 -06:00
|
|
|
fn nc() -> NC {
|
|
|
|
NC
|
|
|
|
}
|
2019-12-14 20:50:55 -06:00
|
|
|
|
2019-11-11 04:39:52 -06:00
|
|
|
fn main() {
|
|
|
|
let a @ box &b = Box::new(&C);
|
|
|
|
|
|
|
|
let a @ box b = Box::new(C);
|
|
|
|
|
2019-12-14 20:50:55 -06:00
|
|
|
fn f1(a @ box &b: Box<&C>) {}
|
|
|
|
|
|
|
|
fn f2(a @ box b: Box<C>) {}
|
|
|
|
|
2020-01-18 19:47:01 -06:00
|
|
|
match Box::new(C) {
|
2020-11-01 12:35:55 -06:00
|
|
|
a @ box b => {}
|
2020-01-18 19:47:01 -06:00
|
|
|
}
|
2019-12-14 20:50:55 -06:00
|
|
|
|
2020-02-02 10:58:15 -06:00
|
|
|
let ref a @ box b = Box::new(NC); //~ ERROR cannot move out of value because it is borrowed
|
2020-11-01 12:35:55 -06:00
|
|
|
//~| ERROR borrow of moved value
|
2019-11-11 04:39:52 -06:00
|
|
|
|
2019-12-14 17:50:44 -06:00
|
|
|
let ref a @ box ref mut b = Box::new(nc());
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
2019-12-14 17:32:20 -06:00
|
|
|
let ref a @ box ref mut b = Box::new(NC);
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
2019-12-14 17:32:20 -06:00
|
|
|
let ref a @ box ref mut b = Box::new(NC);
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
2020-11-01 12:35:55 -06:00
|
|
|
//~| ERROR cannot borrow value as immutable because it is also borrowed as mutable
|
2019-11-11 04:39:52 -06:00
|
|
|
*b = NC;
|
|
|
|
let ref a @ box ref mut b = Box::new(NC);
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
2020-11-01 12:35:55 -06:00
|
|
|
//~| ERROR cannot borrow value as immutable because it is also borrowed as mutable
|
2019-11-11 04:39:52 -06:00
|
|
|
*b = NC;
|
|
|
|
drop(a);
|
|
|
|
|
|
|
|
let ref mut a @ box ref b = Box::new(NC);
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
|
2020-11-01 12:35:55 -06:00
|
|
|
//~| ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
2019-11-11 04:39:52 -06:00
|
|
|
*a = Box::new(NC);
|
|
|
|
drop(b);
|
2019-12-14 20:50:55 -06:00
|
|
|
|
|
|
|
fn f5(ref mut a @ box ref b: Box<NC>) {
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
|
2020-11-01 12:35:55 -06:00
|
|
|
//~| ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
2019-12-14 20:50:55 -06:00
|
|
|
*a = Box::new(NC);
|
|
|
|
drop(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
match Box::new(nc()) {
|
|
|
|
ref mut a @ box ref b => {
|
2020-02-02 10:58:15 -06:00
|
|
|
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
|
2020-11-01 12:35:55 -06:00
|
|
|
//~| ERROR cannot borrow value as mutable because it is also borrowed as immutable
|
2019-12-14 20:50:55 -06:00
|
|
|
*a = Box::new(NC);
|
|
|
|
drop(b);
|
|
|
|
}
|
|
|
|
}
|
2019-11-11 04:39:52 -06:00
|
|
|
}
|