2018-09-04 05:05:53 -05:00
|
|
|
// run-pass
|
2018-09-25 16:51:35 -05:00
|
|
|
#![allow(unused_mut)]
|
|
|
|
#![allow(unused_variables)]
|
2023-05-19 04:14:55 -05:00
|
|
|
#![allow(dropping_copy_types)]
|
2015-03-22 15:13:15 -05:00
|
|
|
// pretty-expanded FIXME #23616
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
struct A { a: isize, b: Box<isize> }
|
|
|
|
struct B { a: Box<isize>, b: Box<isize> }
|
2014-06-06 13:59:33 -05:00
|
|
|
|
2014-06-07 02:29:24 -05:00
|
|
|
fn move_after_copy() {
|
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.a);
|
|
|
|
drop(x.b);
|
|
|
|
}
|
|
|
|
|
2014-06-07 02:29:24 -05:00
|
|
|
fn move_after_fu_copy() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = A { a: 1, b: Box::new(2) };
|
|
|
|
let _y = A { b: Box::new(3), .. x };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.b);
|
|
|
|
}
|
|
|
|
|
2014-06-07 02:29:24 -05:00
|
|
|
fn fu_move_after_copy() {
|
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.a);
|
2014-06-07 04:20:44 -05:00
|
|
|
let _y = A { a: 3, .. x };
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
2014-06-07 02:29:24 -05:00
|
|
|
fn fu_move_after_fu_copy() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = A { a: 1, b: Box::new(2) };
|
|
|
|
let _y = A { b: Box::new(3), .. x };
|
2014-06-07 04:20:44 -05:00
|
|
|
let _z = A { a: 4, .. x };
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
2014-06-07 02:29:24 -05:00
|
|
|
fn copy_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.a);
|
|
|
|
}
|
|
|
|
|
2014-06-07 02:29:24 -05:00
|
|
|
fn copy_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.a);
|
|
|
|
}
|
|
|
|
|
2014-06-07 02:29:24 -05:00
|
|
|
fn fu_copy_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);
|
2021-08-24 19:39:40 -05:00
|
|
|
let _y = A { b: Box::new(3), .. x };
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
2014-06-07 02:29:24 -05:00
|
|
|
fn fu_copy_after_fu_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = A { a: 1, b: Box::new(2) };
|
2014-06-07 04:20:44 -05:00
|
|
|
let _y = A { a: 3, .. x };
|
2021-08-24 19:39:40 -05:00
|
|
|
let _z = A { b: Box::new(3), .. x };
|
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);
|
2014-06-07 04:55:00 -05:00
|
|
|
let p = &x.a;
|
|
|
|
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-07 04:20:44 -05:00
|
|
|
let _y = A { a: 3, .. x };
|
2014-06-07 04:55:00 -05:00
|
|
|
let p = &x.a;
|
|
|
|
drop(*p);
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
2014-06-13 22:48:09 -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-13 22:48:09 -05:00
|
|
|
let p = &x.a;
|
|
|
|
drop(x.b);
|
|
|
|
drop(*p);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fu_move_after_borrow() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = A { a: 1, b: Box::new(2) };
|
2014-06-13 22:48:09 -05:00
|
|
|
let p = &x.a;
|
|
|
|
let _y = A { a: 3, .. x };
|
|
|
|
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.b;
|
|
|
|
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 = B { a: Box::new(1), b: Box::new(2) };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.a);
|
|
|
|
drop(x.b);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn move_after_fu_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = B { a: Box::new(1), b: Box::new(2) };
|
|
|
|
let y = B { a: Box::new(3), .. x };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.a);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fu_move_after_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = B { a: Box::new(1), b: Box::new(2) };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.a);
|
2021-08-24 19:39:40 -05:00
|
|
|
let z = B { a: Box::new(3), .. x };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(z.b);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fu_move_after_fu_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = B { a: Box::new(1), b: Box::new(2) };
|
|
|
|
let _y = B { b: Box::new(3), .. x };
|
|
|
|
let _z = B { a: Box::new(4), .. x };
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
2014-06-07 02:29:24 -05:00
|
|
|
fn copy_after_assign_after_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut x = A { a: 1, b: Box::new(2) };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.b);
|
2021-08-24 19:39:40 -05:00
|
|
|
x = A { a: 3, b: Box::new(4) };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(*x.b);
|
|
|
|
}
|
|
|
|
|
2014-06-07 02:44:01 -05:00
|
|
|
fn copy_after_assign_after_fu_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut x = A { a: 1, b: Box::new(2) };
|
2014-06-07 02:44:01 -05:00
|
|
|
let _y = A { a: 3, .. x };
|
2021-08-24 19:39:40 -05:00
|
|
|
x = A { a: 3, b: Box::new(4) };
|
2014-06-07 02:44:01 -05:00
|
|
|
drop(*x.b);
|
|
|
|
}
|
|
|
|
|
2014-06-07 02:29:24 -05:00
|
|
|
fn copy_after_field_assign_after_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut x = A { a: 1, b: Box::new(2) };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.b);
|
2021-08-24 19:39:40 -05:00
|
|
|
x.b = Box::new(3);
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(*x.b);
|
|
|
|
}
|
|
|
|
|
2014-06-07 02:44:01 -05:00
|
|
|
fn copy_after_field_assign_after_fu_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut x = A { a: 1, b: Box::new(2) };
|
2014-06-07 02:44:01 -05:00
|
|
|
let _y = A { a: 3, .. x };
|
2021-08-24 19:39:40 -05:00
|
|
|
x.b = Box::new(3);
|
2014-06-07 02:44:01 -05:00
|
|
|
drop(*x.b);
|
|
|
|
}
|
|
|
|
|
2014-06-06 13:59:33 -05:00
|
|
|
fn borrow_after_assign_after_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut x = A { a: 1, b: Box::new(2) };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.b);
|
2021-08-24 19:39:40 -05:00
|
|
|
x = A { a: 3, b: Box::new(4) };
|
2014-06-07 04:55:00 -05:00
|
|
|
let p = &x.b;
|
|
|
|
drop(**p);
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
2014-06-07 02:44:01 -05:00
|
|
|
fn borrow_after_assign_after_fu_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut x = A { a: 1, b: Box::new(2) };
|
2014-06-07 02:44:01 -05:00
|
|
|
let _y = A { a: 3, .. x };
|
2021-08-24 19:39:40 -05:00
|
|
|
x = A { a: 3, b: Box::new(4) };
|
2014-06-07 04:55:00 -05:00
|
|
|
let p = &x.b;
|
|
|
|
drop(**p);
|
2014-06-07 02:44:01 -05:00
|
|
|
}
|
|
|
|
|
2014-06-06 13:59:33 -05:00
|
|
|
fn borrow_after_field_assign_after_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut x = A { a: 1, b: Box::new(2) };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.b);
|
2021-08-24 19:39:40 -05:00
|
|
|
x.b = Box::new(3);
|
2014-06-07 04:55:00 -05:00
|
|
|
let p = &x.b;
|
|
|
|
drop(**p);
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
2014-06-07 02:44:01 -05:00
|
|
|
fn borrow_after_field_assign_after_fu_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut x = A { a: 1, b: Box::new(2) };
|
2014-06-07 02:44:01 -05:00
|
|
|
let _y = A { a: 3, .. x };
|
2021-08-24 19:39:40 -05:00
|
|
|
x.b = Box::new(3);
|
2014-06-07 04:55:00 -05:00
|
|
|
let p = &x.b;
|
|
|
|
drop(**p);
|
2014-06-07 02:44:01 -05:00
|
|
|
}
|
|
|
|
|
2014-06-06 13:59:33 -05:00
|
|
|
fn move_after_assign_after_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut x = A { a: 1, b: Box::new(2) };
|
2014-06-07 04:20:44 -05:00
|
|
|
let _y = x.b;
|
2021-08-24 19:39:40 -05:00
|
|
|
x = A { a: 3, b: Box::new(4) };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.b);
|
|
|
|
}
|
|
|
|
|
2014-06-07 02:44:01 -05:00
|
|
|
fn move_after_assign_after_fu_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut x = A { a: 1, b: Box::new(2) };
|
2014-06-07 02:44:01 -05:00
|
|
|
let _y = A { a: 3, .. x };
|
2021-08-24 19:39:40 -05:00
|
|
|
x = A { a: 3, b: Box::new(4) };
|
2014-06-07 02:44:01 -05:00
|
|
|
drop(x.b);
|
|
|
|
}
|
|
|
|
|
2014-06-06 13:59:33 -05:00
|
|
|
fn move_after_field_assign_after_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut x = A { a: 1, b: Box::new(2) };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.b);
|
2021-08-24 19:39:40 -05:00
|
|
|
x.b = Box::new(3);
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.b);
|
|
|
|
}
|
|
|
|
|
2014-06-07 02:44:01 -05:00
|
|
|
fn move_after_field_assign_after_fu_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut x = A { a: 1, b: Box::new(2) };
|
2014-06-07 02:44:01 -05:00
|
|
|
let _y = A { a: 3, .. x };
|
2021-08-24 19:39:40 -05:00
|
|
|
x.b = Box::new(3);
|
2014-06-07 02:44:01 -05:00
|
|
|
drop(x.b);
|
|
|
|
}
|
|
|
|
|
2014-06-07 02:29:24 -05:00
|
|
|
fn copy_after_assign_after_uninit() {
|
2014-06-06 13:59:33 -05:00
|
|
|
let mut x: A;
|
2021-08-24 19:39:40 -05:00
|
|
|
x = A { a: 1, b: Box::new(2) };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.a);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn borrow_after_assign_after_uninit() {
|
|
|
|
let mut x: A;
|
2021-08-24 19:39:40 -05:00
|
|
|
x = A { a: 1, b: Box::new(2) };
|
2014-06-07 04:55:00 -05:00
|
|
|
let p = &x.a;
|
|
|
|
drop(*p);
|
2014-06-06 13:59:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn move_after_assign_after_uninit() {
|
|
|
|
let mut x: A;
|
2021-08-24 19:39:40 -05:00
|
|
|
x = A { a: 1, b: Box::new(2) };
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x.b);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2014-06-07 02:29:24 -05:00
|
|
|
move_after_copy();
|
|
|
|
move_after_fu_copy();
|
|
|
|
fu_move_after_copy();
|
|
|
|
fu_move_after_fu_copy();
|
|
|
|
copy_after_move();
|
|
|
|
copy_after_fu_move();
|
|
|
|
fu_copy_after_move();
|
|
|
|
fu_copy_after_fu_move();
|
2014-06-06 13:59:33 -05:00
|
|
|
|
|
|
|
borrow_after_move();
|
|
|
|
borrow_after_fu_move();
|
2014-06-13 22:48:09 -05:00
|
|
|
move_after_borrow();
|
|
|
|
fu_move_after_borrow();
|
2014-06-06 13:59:33 -05:00
|
|
|
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_assign_after_move();
|
2014-06-07 02:44:01 -05:00
|
|
|
copy_after_assign_after_fu_move();
|
2014-06-07 02:29:24 -05:00
|
|
|
copy_after_field_assign_after_move();
|
2014-06-07 02:44:01 -05:00
|
|
|
copy_after_field_assign_after_fu_move();
|
|
|
|
|
2014-06-06 13:59:33 -05:00
|
|
|
borrow_after_assign_after_move();
|
2014-06-07 02:44:01 -05:00
|
|
|
borrow_after_assign_after_fu_move();
|
2014-06-06 13:59:33 -05:00
|
|
|
borrow_after_field_assign_after_move();
|
2014-06-07 02:44:01 -05:00
|
|
|
borrow_after_field_assign_after_fu_move();
|
|
|
|
|
2014-06-06 13:59:33 -05:00
|
|
|
move_after_assign_after_move();
|
2014-06-07 02:44:01 -05:00
|
|
|
move_after_assign_after_fu_move();
|
2014-06-06 13:59:33 -05:00
|
|
|
move_after_field_assign_after_move();
|
2014-06-07 02:44:01 -05:00
|
|
|
move_after_field_assign_after_fu_move();
|
2014-06-06 13:59:33 -05:00
|
|
|
|
2014-06-07 02:29:24 -05:00
|
|
|
copy_after_assign_after_uninit();
|
2014-06-06 13:59:33 -05:00
|
|
|
borrow_after_assign_after_uninit();
|
|
|
|
move_after_assign_after_uninit();
|
|
|
|
}
|