2015-01-08 04:54:35 -06:00
|
|
|
struct A { a: isize, b: Box<isize> }
|
2014-06-06 13:59:33 -05:00
|
|
|
|
2021-08-24 19:39:40 -05:00
|
|
|
|
|
|
|
|
2014-06-07 02:29:24 -05:00
|
|
|
fn deref_after_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = A { a: 1, b: Box::new(2) };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.b);
|
2019-04-22 02:40:08 -05:00
|
|
|
drop(*x.b); //~ ERROR use of moved value: `x.b`
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
2014-06-07 02:29:24 -05:00
|
|
|
fn deref_after_fu_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = A { a: 1, b: Box::new(2) };
|
2014-06-06 13:59:33 -05:00
|
|
|
let y = A { a: 3, .. x };
|
2019-04-22 02:40:08 -05:00
|
|
|
drop(*x.b); //~ ERROR use of moved value: `x.b`
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn borrow_after_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = A { a: 1, b: Box::new(2) };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.b);
|
2019-04-22 02:40:08 -05:00
|
|
|
let p = &x.b; //~ ERROR borrow of moved value: `x.b`
|
2014-06-07 04:55:00 -05:00
|
|
|
drop(**p);
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn borrow_after_fu_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = A { a: 1, b: Box::new(2) };
|
2014-06-06 13:59:33 -05:00
|
|
|
let _y = A { a: 3, .. x };
|
2019-04-22 02:40:08 -05:00
|
|
|
let p = &x.b; //~ ERROR borrow of moved value: `x.b`
|
2014-06-07 04:55:00 -05:00
|
|
|
drop(**p);
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn move_after_borrow() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = A { a: 1, b: Box::new(2) };
|
2014-06-07 04:55:00 -05:00
|
|
|
let p = &x.b;
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.b); //~ ERROR cannot move out of `x.b` because it is borrowed
|
2014-06-07 04:55:00 -05:00
|
|
|
drop(**p);
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn fu_move_after_borrow() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = A { a: 1, b: Box::new(2) };
|
2014-06-07 04:55:00 -05:00
|
|
|
let p = &x.b;
|
|
|
|
let _y = A { a: 3, .. x }; //~ ERROR cannot move out of `x.b` because it is borrowed
|
|
|
|
drop(**p);
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn mut_borrow_after_mut_borrow() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut x = A { a: 1, b: Box::new(2) };
|
2014-06-07 04:55:00 -05:00
|
|
|
let p = &mut x.a;
|
|
|
|
let q = &mut x.a; //~ ERROR cannot borrow `x.a` as mutable more than once at a time
|
|
|
|
drop(*p);
|
|
|
|
drop(*q);
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn move_after_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = A { a: 1, b: Box::new(2) };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.b);
|
|
|
|
drop(x.b); //~ ERROR use of moved value: `x.b`
|
|
|
|
}
|
|
|
|
|
|
|
|
fn move_after_fu_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = A { a: 1, b: Box::new(2) };
|
2014-06-06 13:59:33 -05:00
|
|
|
let _y = A { a: 3, .. x };
|
|
|
|
drop(x.b); //~ ERROR use of moved value: `x.b`
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fu_move_after_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = A { a: 1, b: Box::new(2) };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.b);
|
|
|
|
let _z = A { a: 3, .. x }; //~ ERROR use of moved value: `x.b`
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fu_move_after_fu_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = A { a: 1, b: Box::new(2) };
|
2014-06-06 13:59:33 -05:00
|
|
|
let _y = A { a: 3, .. x };
|
|
|
|
let _z = A { a: 4, .. x }; //~ ERROR use of moved value: `x.b`
|
|
|
|
}
|
|
|
|
|
|
|
|
// The following functions aren't yet accepted, but they should be.
|
|
|
|
|
2014-06-07 02:29:24 -05:00
|
|
|
fn copy_after_field_assign_after_uninit() {
|
2014-06-06 13:59:33 -05:00
|
|
|
let mut x: A;
|
2019-09-01 12:09:59 -05:00
|
|
|
x.a = 1; //~ ERROR assign to part of possibly-uninitialized variable: `x`
|
2019-04-22 02:40:08 -05:00
|
|
|
drop(x.a);
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn borrow_after_field_assign_after_uninit() {
|
|
|
|
let mut x: A;
|
2019-09-01 12:09:59 -05:00
|
|
|
x.a = 1; //~ ERROR assign to part of possibly-uninitialized variable: `x`
|
2019-04-22 02:40:08 -05:00
|
|
|
let p = &x.a;
|
2014-06-07 04:55:00 -05:00
|
|
|
drop(*p);
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn move_after_field_assign_after_uninit() {
|
|
|
|
let mut x: A;
|
2021-08-24 19:39:40 -05:00
|
|
|
x.b = Box::new(1); //~ ERROR assign to part of possibly-uninitialized variable: `x`
|
2019-04-22 02:40:08 -05:00
|
|
|
drop(x.b);
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2014-06-07 02:29:24 -05:00
|
|
|
deref_after_move();
|
|
|
|
deref_after_fu_move();
|
2014-06-06 13:59:33 -05:00
|
|
|
|
|
|
|
borrow_after_move();
|
|
|
|
borrow_after_fu_move();
|
|
|
|
move_after_borrow();
|
|
|
|
fu_move_after_borrow();
|
|
|
|
mut_borrow_after_mut_borrow();
|
|
|
|
|
|
|
|
move_after_move();
|
|
|
|
move_after_fu_move();
|
|
|
|
fu_move_after_move();
|
|
|
|
fu_move_after_fu_move();
|
|
|
|
|
2014-06-07 02:29:24 -05:00
|
|
|
copy_after_field_assign_after_uninit();
|
2014-06-06 13:59:33 -05:00
|
|
|
borrow_after_field_assign_after_uninit();
|
|
|
|
move_after_field_assign_after_uninit();
|
|
|
|
}
|