]> git.lizzy.rs Git - rust.git/blob - library/core/tests/manually_drop.rs
Rollup merge of #103554 - notriddle:notriddle/summary-focus-visible, r=jsha
[rust.git] / library / core / tests / manually_drop.rs
1 use core::mem::ManuallyDrop;
2
3 #[test]
4 fn smoke() {
5     #[derive(Clone)]
6     struct TypeWithDrop;
7     impl Drop for TypeWithDrop {
8         fn drop(&mut self) {
9             unreachable!("Should not get dropped");
10         }
11     }
12
13     let x = ManuallyDrop::new(TypeWithDrop);
14     drop(x);
15
16     // also test unsizing
17     let x: Box<ManuallyDrop<[TypeWithDrop]>> =
18         Box::new(ManuallyDrop::new([TypeWithDrop, TypeWithDrop]));
19     drop(x);
20
21     // test clone and clone_from implementations
22     let mut x = ManuallyDrop::new(TypeWithDrop);
23     let y = x.clone();
24     x.clone_from(&y);
25     drop(x);
26     drop(y);
27 }