]> git.proxmox.com Git - rustc.git/blob - src/test/codegen-units/partitioning/vtable-through-const.rs
New upstream version 1.52.0~beta.3+dfsg1
[rustc.git] / src / test / codegen-units / partitioning / vtable-through-const.rs
1 // ignore-tidy-linelength
2
3 // We specify -C incremental here because we want to test the partitioning for
4 // incremental compilation
5 // compile-flags:-Zprint-mono-items=lazy -Cincremental=tmp/partitioning-tests/vtable-through-const
6 // compile-flags:-Zinline-in-all-cgus
7
8 // This test case makes sure, that references made through constants are
9 // recorded properly in the InliningMap.
10
11 #![feature(start)]
12
13 mod mod1 {
14 pub trait Trait1 {
15 fn do_something(&self) {}
16 fn do_something_else(&self) {}
17 }
18
19 impl Trait1 for u32 {}
20
21 pub trait Trait1Gen<T> {
22 fn do_something(&self, x: T) -> T;
23 fn do_something_else(&self, x: T) -> T;
24 }
25
26 impl<T> Trait1Gen<T> for u32 {
27 fn do_something(&self, x: T) -> T { x }
28 fn do_something_else(&self, x: T) -> T { x }
29 }
30
31 //~ MONO_ITEM fn mod1::id::<i64> @@ vtable_through_const-mod1.volatile[Internal]
32 fn id<T>(x: T) -> T { x }
33
34 // These are referenced, so they produce mono-items (see start())
35 pub const TRAIT1_REF: &'static Trait1 = &0u32 as &Trait1;
36 pub const TRAIT1_GEN_REF: &'static Trait1Gen<u8> = &0u32 as &Trait1Gen<u8>;
37 pub const ID_CHAR: fn(char) -> char = id::<char>;
38
39
40
41 pub trait Trait2 {
42 fn do_something(&self) {}
43 fn do_something_else(&self) {}
44 }
45
46 //~ MONO_ITEM fn <u32 as mod1::Trait2>::do_something @@ vtable_through_const-mod1.volatile[Internal]
47 //~ MONO_ITEM fn <u32 as mod1::Trait2>::do_something_else @@ vtable_through_const-mod1.volatile[Internal]
48 impl Trait2 for u32 {}
49
50 pub trait Trait2Gen<T> {
51 fn do_something(&self, x: T) -> T;
52 fn do_something_else(&self, x: T) -> T;
53 }
54
55 impl<T> Trait2Gen<T> for u32 {
56 fn do_something(&self, x: T) -> T { x }
57 fn do_something_else(&self, x: T) -> T { x }
58 }
59
60 // These are not referenced, so they do not produce mono-items
61 pub const TRAIT2_REF: &'static Trait2 = &0u32 as &Trait2;
62 pub const TRAIT2_GEN_REF: &'static Trait2Gen<u8> = &0u32 as &Trait2Gen<u8>;
63 pub const ID_I64: fn(i64) -> i64 = id::<i64>;
64 }
65
66 //~ MONO_ITEM fn start
67 #[start]
68 fn start(_: isize, _: *const *const u8) -> isize {
69 //~ MONO_ITEM fn std::ptr::drop_in_place::<u32> - shim(None) @@ vtable_through_const[Internal]
70
71 // Since Trait1::do_something() is instantiated via its default implementation,
72 // it is considered a generic and is instantiated here only because it is
73 // referenced in this module.
74 //~ MONO_ITEM fn <u32 as mod1::Trait1>::do_something_else @@ vtable_through_const-mod1.volatile[External]
75
76 // Although it is never used, Trait1::do_something_else() has to be
77 // instantiated locally here too, otherwise the <&u32 as &Trait1> vtable
78 // could not be fully constructed.
79 //~ MONO_ITEM fn <u32 as mod1::Trait1>::do_something @@ vtable_through_const-mod1.volatile[External]
80 mod1::TRAIT1_REF.do_something();
81
82 // Same as above
83 //~ MONO_ITEM fn <u32 as mod1::Trait1Gen<u8>>::do_something @@ vtable_through_const-mod1.volatile[External]
84 //~ MONO_ITEM fn <u32 as mod1::Trait1Gen<u8>>::do_something_else @@ vtable_through_const-mod1.volatile[External]
85 //~ MONO_ITEM fn <u32 as mod1::Trait2Gen<u8>>::do_something @@ vtable_through_const-mod1.volatile[Internal]
86 //~ MONO_ITEM fn <u32 as mod1::Trait2Gen<u8>>::do_something_else @@ vtable_through_const-mod1.volatile[Internal]
87 mod1::TRAIT1_GEN_REF.do_something(0u8);
88
89 //~ MONO_ITEM fn mod1::id::<char> @@ vtable_through_const-mod1.volatile[External]
90 mod1::ID_CHAR('x');
91
92 0
93 }