]> git.lizzy.rs Git - rust.git/blob - src/test/codegen-units/item-collection/generic-drop-glue.rs
Deprecate items that accidentally weren't deprecated
[rust.git] / src / test / codegen-units / item-collection / generic-drop-glue.rs
1 // ignore-tidy-linelength
2 // compile-flags:-Zprint-mono-items=eager
3 // compile-flags:-Zinline-in-all-cgus
4
5 #![deny(dead_code)]
6 #![feature(start)]
7
8 struct StructWithDrop<T1, T2> {
9     x: T1,
10     y: T2,
11 }
12
13 impl<T1, T2> Drop for StructWithDrop<T1, T2> {
14     fn drop(&mut self) {}
15 }
16
17 struct StructNoDrop<T1, T2> {
18     x: T1,
19     y: T2,
20 }
21
22 enum EnumWithDrop<T1, T2> {
23     A(T1),
24     B(T2)
25 }
26
27 impl<T1, T2> Drop for EnumWithDrop<T1, T2> {
28     fn drop(&mut self) {}
29 }
30
31 enum EnumNoDrop<T1, T2> {
32     A(T1),
33     B(T2)
34 }
35
36
37 struct NonGenericNoDrop(i32);
38
39 struct NonGenericWithDrop(i32);
40 //~ MONO_ITEM fn std::ptr::drop_in_place::<NonGenericWithDrop> - shim(Some(NonGenericWithDrop)) @@ generic_drop_glue-cgu.0[Internal]
41
42 impl Drop for NonGenericWithDrop {
43     //~ MONO_ITEM fn <NonGenericWithDrop as std::ops::Drop>::drop
44     fn drop(&mut self) {}
45 }
46
47 //~ MONO_ITEM fn start
48 #[start]
49 fn start(_: isize, _: *const *const u8) -> isize {
50     //~ MONO_ITEM fn std::ptr::drop_in_place::<StructWithDrop<i8, char>> - shim(Some(StructWithDrop<i8, char>)) @@ generic_drop_glue-cgu.0[Internal]
51     //~ MONO_ITEM fn <StructWithDrop<i8, char> as std::ops::Drop>::drop
52     let _ = StructWithDrop { x: 0i8, y: 'a' }.x;
53
54     //~ MONO_ITEM fn std::ptr::drop_in_place::<StructWithDrop<&str, NonGenericNoDrop>> - shim(Some(StructWithDrop<&str, NonGenericNoDrop>)) @@ generic_drop_glue-cgu.0[Internal]
55     //~ MONO_ITEM fn <StructWithDrop<&str, NonGenericNoDrop> as std::ops::Drop>::drop
56     let _ = StructWithDrop { x: "&str", y: NonGenericNoDrop(0) }.y;
57
58     // Should produce no drop glue
59     let _ = StructNoDrop { x: 'a', y: 0u32 }.x;
60
61     // This is supposed to generate drop-glue because it contains a field that
62     // needs to be dropped.
63     //~ MONO_ITEM fn std::ptr::drop_in_place::<StructNoDrop<NonGenericWithDrop, f64>> - shim(Some(StructNoDrop<NonGenericWithDrop, f64>)) @@ generic_drop_glue-cgu.0[Internal]
64     let _ = StructNoDrop { x: NonGenericWithDrop(0), y: 0f64 }.y;
65
66     //~ MONO_ITEM fn std::ptr::drop_in_place::<EnumWithDrop<i32, i64>> - shim(Some(EnumWithDrop<i32, i64>)) @@ generic_drop_glue-cgu.0[Internal]
67     //~ MONO_ITEM fn <EnumWithDrop<i32, i64> as std::ops::Drop>::drop
68     let _ = match EnumWithDrop::A::<i32, i64>(0) {
69         EnumWithDrop::A(x) => x,
70         EnumWithDrop::B(x) => x as i32
71     };
72
73     //~ MONO_ITEM fn std::ptr::drop_in_place::<EnumWithDrop<f64, f32>> - shim(Some(EnumWithDrop<f64, f32>)) @@ generic_drop_glue-cgu.0[Internal]
74     //~ MONO_ITEM fn <EnumWithDrop<f64, f32> as std::ops::Drop>::drop
75     let _ = match EnumWithDrop::B::<f64, f32>(1.0) {
76         EnumWithDrop::A(x) => x,
77         EnumWithDrop::B(x) => x as f64
78     };
79
80     let _ = match EnumNoDrop::A::<i32, i64>(0) {
81         EnumNoDrop::A(x) => x,
82         EnumNoDrop::B(x) => x as i32
83     };
84
85     let _ = match EnumNoDrop::B::<f64, f32>(1.0) {
86         EnumNoDrop::A(x) => x,
87         EnumNoDrop::B(x) => x as f64
88     };
89
90     0
91 }