]> git.proxmox.com Git - rustc.git/blob - src/test/codegen-units/item-collection/generic-drop-glue.rs
New upstream version 1.24.1+dfsg1
[rustc.git] / src / test / codegen-units / item-collection / generic-drop-glue.rs
1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // ignore-tidy-linelength
12 // compile-flags:-Zprint-trans-items=eager
13 // compile-flags:-Zinline-in-all-cgus
14
15 #![deny(dead_code)]
16 #![feature(start)]
17
18 struct StructWithDrop<T1, T2> {
19 x: T1,
20 y: T2,
21 }
22
23 impl<T1, T2> Drop for StructWithDrop<T1, T2> {
24 fn drop(&mut self) {}
25 }
26
27 struct StructNoDrop<T1, T2> {
28 x: T1,
29 y: T2,
30 }
31
32 enum EnumWithDrop<T1, T2> {
33 A(T1),
34 B(T2)
35 }
36
37 impl<T1, T2> Drop for EnumWithDrop<T1, T2> {
38 fn drop(&mut self) {}
39 }
40
41 enum EnumNoDrop<T1, T2> {
42 A(T1),
43 B(T2)
44 }
45
46
47 struct NonGenericNoDrop(i32);
48
49 struct NonGenericWithDrop(i32);
50 //~ TRANS_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::NonGenericWithDrop[0]> @@ generic_drop_glue0[Internal]
51
52 impl Drop for NonGenericWithDrop {
53 //~ TRANS_ITEM fn generic_drop_glue::{{impl}}[2]::drop[0]
54 fn drop(&mut self) {}
55 }
56
57 //~ TRANS_ITEM fn generic_drop_glue::start[0]
58 #[start]
59 fn start(_: isize, _: *const *const u8) -> isize {
60 //~ TRANS_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::StructWithDrop[0]<i8, char>> @@ generic_drop_glue0[Internal]
61 //~ TRANS_ITEM fn generic_drop_glue::{{impl}}[0]::drop[0]<i8, char>
62 let _ = StructWithDrop { x: 0i8, y: 'a' }.x;
63
64 //~ TRANS_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::StructWithDrop[0]<&str, generic_drop_glue::NonGenericNoDrop[0]>> @@ generic_drop_glue0[Internal]
65 //~ TRANS_ITEM fn generic_drop_glue::{{impl}}[0]::drop[0]<&str, generic_drop_glue::NonGenericNoDrop[0]>
66 let _ = StructWithDrop { x: "&str", y: NonGenericNoDrop(0) }.y;
67
68 // Should produce no drop glue
69 let _ = StructNoDrop { x: 'a', y: 0u32 }.x;
70
71 // This is supposed to generate drop-glue because it contains a field that
72 // needs to be dropped.
73 //~ TRANS_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::StructNoDrop[0]<generic_drop_glue::NonGenericWithDrop[0], f64>> @@ generic_drop_glue0[Internal]
74 let _ = StructNoDrop { x: NonGenericWithDrop(0), y: 0f64 }.y;
75
76 //~ TRANS_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::EnumWithDrop[0]<i32, i64>> @@ generic_drop_glue0[Internal]
77 //~ TRANS_ITEM fn generic_drop_glue::{{impl}}[1]::drop[0]<i32, i64>
78 let _ = match EnumWithDrop::A::<i32, i64>(0) {
79 EnumWithDrop::A(x) => x,
80 EnumWithDrop::B(x) => x as i32
81 };
82
83 //~TRANS_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::EnumWithDrop[0]<f64, f32>> @@ generic_drop_glue0[Internal]
84 //~ TRANS_ITEM fn generic_drop_glue::{{impl}}[1]::drop[0]<f64, f32>
85 let _ = match EnumWithDrop::B::<f64, f32>(1.0) {
86 EnumWithDrop::A(x) => x,
87 EnumWithDrop::B(x) => x as f64
88 };
89
90 let _ = match EnumNoDrop::A::<i32, i64>(0) {
91 EnumNoDrop::A(x) => x,
92 EnumNoDrop::B(x) => x as i32
93 };
94
95 let _ = match EnumNoDrop::B::<f64, f32>(1.0) {
96 EnumNoDrop::A(x) => x,
97 EnumNoDrop::B(x) => x as f64
98 };
99
100 0
101 }