]> git.lizzy.rs Git - rust.git/blob - tests/ui/drop_forget_copy.rs
Merge pull request #3291 from JoshMcguigan/cmp_owned-3289
[rust.git] / tests / ui / drop_forget_copy.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10
11
12
13
14 #![warn(clippy::drop_copy, clippy::forget_copy)]
15 #![allow(clippy::toplevel_ref_arg, clippy::drop_ref, clippy::forget_ref, unused_mut)]
16
17 use std::mem::{drop, forget};
18 use std::vec::Vec;
19
20 #[derive(Copy, Clone)]
21 struct SomeStruct {
22 }
23
24 struct AnotherStruct {
25     x: u8,
26     y: u8,
27     z: Vec<u8>
28 }
29
30 impl Clone for AnotherStruct {
31     fn clone(& self) -> AnotherStruct {
32         AnotherStruct{x: self.x, y: self.y, z: self.z.clone()}
33     }
34 }
35
36 fn main() {
37     let s1 = SomeStruct {};
38     let s2 = s1;
39     let s3 = &s1;
40     let mut s4 = s1;
41     let ref s5 = s1;
42
43     drop(s1);
44     drop(s2);
45     drop(s3);
46     drop(s4);
47     drop(s5);
48
49     forget(s1);
50     forget(s2);
51     forget(s3);
52     forget(s4);
53     forget(s5);
54
55     let a1 = AnotherStruct {x: 255, y: 0, z: vec![1, 2, 3]};
56     let a2 = &a1;
57     let mut a3 = a1.clone();
58     let ref a4 = a1;
59     let a5 = a1.clone();
60
61     drop(a2);
62     drop(a3);
63     drop(a4);
64     drop(a5);
65
66     forget(a2);
67     let a3 = &a1;
68     forget(a3);
69     forget(a4);
70     let a5 = a1.clone();
71     forget(a5);
72 }