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