]> git.lizzy.rs Git - rust.git/blob - src/test/codegen-units/item-collection/unsizing.rs
remove pat2021
[rust.git] / src / test / codegen-units / item-collection / unsizing.rs
1 // compile-flags:-Zprint-mono-items=eager
2 // compile-flags:-Zinline-in-all-cgus
3
4 #![deny(dead_code)]
5 #![feature(coerce_unsized)]
6 #![feature(unsize)]
7 #![feature(start)]
8
9 use std::marker::Unsize;
10 use std::ops::CoerceUnsized;
11
12 trait Trait {
13     fn foo(&self);
14 }
15
16 // Simple Case
17 impl Trait for bool {
18     fn foo(&self) {}
19 }
20
21 impl Trait for char {
22     fn foo(&self) {}
23 }
24
25 // Struct Field Case
26 struct Struct<T: ?Sized> {
27     _a: u32,
28     _b: i32,
29     _c: T
30 }
31
32 impl Trait for f64 {
33     fn foo(&self) {}
34 }
35
36 // Custom Coercion Case
37 impl Trait for u32 {
38     fn foo(&self) {}
39 }
40
41 #[derive(Clone, Copy)]
42 struct Wrapper<T: ?Sized>(*const T);
43
44 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Wrapper<U>> for Wrapper<T> {}
45
46 //~ MONO_ITEM fn start
47 #[start]
48 fn start(_: isize, _: *const *const u8) -> isize {
49     // simple case
50     let bool_sized = &true;
51     //~ MONO_ITEM fn std::ptr::drop_in_place::<bool> - shim(None) @@ unsizing-cgu.0[Internal]
52     //~ MONO_ITEM fn <bool as Trait>::foo
53     let _bool_unsized = bool_sized as &Trait;
54
55     let char_sized = &'a';
56
57     //~ MONO_ITEM fn std::ptr::drop_in_place::<char> - shim(None) @@ unsizing-cgu.0[Internal]
58     //~ MONO_ITEM fn <char as Trait>::foo
59     let _char_unsized = char_sized as &Trait;
60
61     // struct field
62     let struct_sized = &Struct {
63         _a: 1,
64         _b: 2,
65         _c: 3.0f64
66     };
67     //~ MONO_ITEM fn std::ptr::drop_in_place::<f64> - shim(None) @@ unsizing-cgu.0[Internal]
68     //~ MONO_ITEM fn <f64 as Trait>::foo
69     let _struct_unsized = struct_sized as &Struct<Trait>;
70
71     // custom coercion
72     let wrapper_sized = Wrapper(&0u32);
73     //~ MONO_ITEM fn std::ptr::drop_in_place::<u32> - shim(None) @@ unsizing-cgu.0[Internal]
74     //~ MONO_ITEM fn <u32 as Trait>::foo
75     let _wrapper_sized = wrapper_sized as Wrapper<Trait>;
76
77     0
78 }