]> git.proxmox.com Git - rustc.git/blob - src/test/codegen-units/item-collection/generic-drop-glue.rs
Merge tag 'upstream/1.18.0+dfsg1' into debian/experimental
[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
14 #![deny(dead_code)]
15
16 struct StructWithDrop<T1, T2> {
17 x: T1,
18 y: T2,
19 }
20
21 impl<T1, T2> Drop for StructWithDrop<T1, T2> {
22 fn drop(&mut self) {}
23 }
24
25 struct StructNoDrop<T1, T2> {
26 x: T1,
27 y: T2,
28 }
29
30 enum EnumWithDrop<T1, T2> {
31 A(T1),
32 B(T2)
33 }
34
35 impl<T1, T2> Drop for EnumWithDrop<T1, T2> {
36 fn drop(&mut self) {}
37 }
38
39 enum EnumNoDrop<T1, T2> {
40 A(T1),
41 B(T2)
42 }
43
44
45 struct NonGenericNoDrop(i32);
46
47 struct NonGenericWithDrop(i32);
48 //~ TRANS_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::NonGenericWithDrop[0]> @@ generic_drop_glue.cgu-0[Internal]
49
50 impl Drop for NonGenericWithDrop {
51 //~ TRANS_ITEM fn generic_drop_glue::{{impl}}[2]::drop[0]
52 fn drop(&mut self) {}
53 }
54
55 //~ TRANS_ITEM fn generic_drop_glue::main[0]
56 fn main() {
57 //~ TRANS_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::StructWithDrop[0]<i8, char>> @@ generic_drop_glue.cgu-0[Internal]
58 //~ TRANS_ITEM fn generic_drop_glue::{{impl}}[0]::drop[0]<i8, char>
59 let _ = StructWithDrop { x: 0i8, y: 'a' }.x;
60
61 //~ TRANS_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::StructWithDrop[0]<&str, generic_drop_glue::NonGenericNoDrop[0]>> @@ generic_drop_glue.cgu-0[Internal]
62 //~ TRANS_ITEM fn generic_drop_glue::{{impl}}[0]::drop[0]<&str, generic_drop_glue::NonGenericNoDrop[0]>
63 let _ = StructWithDrop { x: "&str", y: NonGenericNoDrop(0) }.y;
64
65 // Should produce no drop glue
66 let _ = StructNoDrop { x: 'a', y: 0u32 }.x;
67
68 // This is supposed to generate drop-glue because it contains a field that
69 // needs to be dropped.
70 //~ TRANS_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::StructNoDrop[0]<generic_drop_glue::NonGenericWithDrop[0], f64>> @@ generic_drop_glue.cgu-0[Internal]
71 let _ = StructNoDrop { x: NonGenericWithDrop(0), y: 0f64 }.y;
72
73 //~ TRANS_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::EnumWithDrop[0]<i32, i64>> @@ generic_drop_glue.cgu-0[Internal]
74 //~ TRANS_ITEM fn generic_drop_glue::{{impl}}[1]::drop[0]<i32, i64>
75 let _ = match EnumWithDrop::A::<i32, i64>(0) {
76 EnumWithDrop::A(x) => x,
77 EnumWithDrop::B(x) => x as i32
78 };
79
80 //~TRANS_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::EnumWithDrop[0]<f64, f32>> @@ generic_drop_glue.cgu-0[Internal]
81 //~ TRANS_ITEM fn generic_drop_glue::{{impl}}[1]::drop[0]<f64, f32>
82 let _ = match EnumWithDrop::B::<f64, f32>(1.0) {
83 EnumWithDrop::A(x) => x,
84 EnumWithDrop::B(x) => x as f64
85 };
86
87 let _ = match EnumNoDrop::A::<i32, i64>(0) {
88 EnumNoDrop::A(x) => x,
89 EnumNoDrop::B(x) => x as i32
90 };
91
92 let _ = match EnumNoDrop::B::<f64, f32>(1.0) {
93 EnumNoDrop::A(x) => x,
94 EnumNoDrop::B(x) => x as f64
95 };
96 }