]> git.lizzy.rs Git - rust.git/blob - tests/ui/drop_forget_copy.rs
Merge branch 'master' into 1537-drop_copy
[rust.git] / tests / ui / drop_forget_copy.rs
1 #![feature(plugin)]
2 #![plugin(clippy)]
3
4 #![deny(drop_copy, forget_copy)]
5 #![allow(toplevel_ref_arg, drop_ref, forget_ref, unused_mut)]
6
7 use std::mem::{drop, forget};
8 use std::vec::Vec;
9
10 #[derive(Copy, Clone)]
11 struct SomeStruct {
12 }
13
14 struct AnotherStruct {
15     x: u8,
16     y: u8,
17     z: Vec<u8>
18 }
19
20 impl Clone for AnotherStruct {
21     fn clone(& self) -> AnotherStruct {
22         AnotherStruct{x: self.x, y: self.y, z: self.z.clone()}
23     }
24 }
25
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 {x: 255, y: 0, z: vec![1, 2, 3]};
46     let a2 = &a1;
47     let mut a3 = a1.clone();
48     let ref a4 = a1;
49     let a5 = a1.clone();
50
51     drop(a2);
52     drop(a3);
53     drop(a4);
54     drop(a5);
55
56     forget(a2);
57     let a3 = &a1;
58     forget(a3);
59     forget(a4);
60     let a5 = a1.clone();
61     forget(a5);
62 }