1 #![warn(clippy::drop_copy, clippy::forget_copy)]
2 #![allow(clippy::toplevel_ref_arg, clippy::drop_ref, clippy::forget_ref, unused_mut)]
3 
4 use std::mem::{drop, forget};
5 use std::vec::Vec;
6 
7 #[derive(Copy, Clone)]
8 struct SomeStruct {}
9 
10 struct AnotherStruct {
11     x: u8,
12     y: u8,
13     z: Vec<u8>,
14 }
15 
16 impl Clone for AnotherStruct {
clone(&self) -> AnotherStruct17     fn clone(&self) -> AnotherStruct {
18         AnotherStruct {
19             x: self.x,
20             y: self.y,
21             z: self.z.clone(),
22         }
23     }
24 }
25 
main()26 fn main() {
27     let s1 = SomeStruct {};
28     let s2 = s1;
29     let s3 = &s1;
30     let mut s4 = s1;
31     let ref s5 = s1;
32 
33     drop(s1);
34     drop(s2);
35     drop(s3);
36     drop(s4);
37     drop(s5);
38 
39     forget(s1);
40     forget(s2);
41     forget(s3);
42     forget(s4);
43     forget(s5);
44 
45     let a1 = AnotherStruct {
46         x: 255,
47         y: 0,
48         z: vec![1, 2, 3],
49     };
50     let a2 = &a1;
51     let mut a3 = a1.clone();
52     let ref a4 = a1;
53     let a5 = a1.clone();
54 
55     drop(a2);
56     drop(a3);
57     drop(a4);
58     drop(a5);
59 
60     forget(a2);
61     let a3 = &a1;
62     forget(a3);
63     forget(a4);
64     let a5 = a1.clone();
65     forget(a5);
66 }
67