2023-07-12 20:38:55 -05:00
|
|
|
#![allow(undropped_manually_drops)]
|
2023-05-13 05:13:37 -05:00
|
|
|
|
2018-07-27 05:12:55 -05:00
|
|
|
use core::mem::ManuallyDrop;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn smoke() {
|
2021-07-05 06:55:45 -05:00
|
|
|
#[derive(Clone)]
|
2018-07-27 05:12:55 -05:00
|
|
|
struct TypeWithDrop;
|
|
|
|
impl Drop for TypeWithDrop {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unreachable!("Should not get dropped");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let x = ManuallyDrop::new(TypeWithDrop);
|
|
|
|
drop(x);
|
2018-08-03 11:02:34 -05:00
|
|
|
|
|
|
|
// also test unsizing
|
2019-12-06 22:18:12 -06:00
|
|
|
let x: Box<ManuallyDrop<[TypeWithDrop]>> =
|
2018-08-06 08:52:36 -05:00
|
|
|
Box::new(ManuallyDrop::new([TypeWithDrop, TypeWithDrop]));
|
2018-08-03 11:02:34 -05:00
|
|
|
drop(x);
|
2021-07-05 06:55:45 -05:00
|
|
|
|
|
|
|
// test clone and clone_from implementations
|
|
|
|
let mut x = ManuallyDrop::new(TypeWithDrop);
|
|
|
|
let y = x.clone();
|
|
|
|
x.clone_from(&y);
|
|
|
|
drop(x);
|
|
|
|
drop(y);
|
2018-07-27 05:12:55 -05:00
|
|
|
}
|