rust/library/core/tests/manually_drop.rs

28 lines
612 B
Rust
Raw Normal View History

2018-07-27 10:12:55 +00:00
use core::mem::ManuallyDrop;
#[test]
fn smoke() {
2021-07-05 11:55:45 +00:00
#[derive(Clone)]
2018-07-27 10:12:55 +00: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 16:02:34 +00:00
// also test unsizing
let x: Box<ManuallyDrop<[TypeWithDrop]>> =
2018-08-06 13:52:36 +00:00
Box::new(ManuallyDrop::new([TypeWithDrop, TypeWithDrop]));
2018-08-03 16:02:34 +00:00
drop(x);
2021-07-05 11:55:45 +00: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 10:12:55 +00:00
}