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.
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.
11 // ignore-tidy-linelength
13 // We specify -Z incremental here because we want to test the partitioning for
14 // incremental compilation
15 // compile-flags:-Zprint-trans-items=lazy -Zincremental=tmp/partitioning-tests/vtable-through-const
17 // This test case makes sure, that references made through constants are
18 // recorded properly in the InliningMap.
22 fn do_something(&self) {}
23 fn do_something_else(&self) {}
26 impl Trait1 for u32 {}
28 pub trait Trait1Gen<T> {
29 fn do_something(&self, x: T) -> T;
30 fn do_something_else(&self, x: T) -> T;
33 impl<T> Trait1Gen<T> for u32 {
34 fn do_something(&self, x: T) -> T { x }
35 fn do_something_else(&self, x: T) -> T { x }
38 fn id<T>(x: T) -> T { x }
40 // These are referenced, so they produce trans-items (see main())
41 pub const TRAIT1_REF: &'static Trait1 = &0u32 as &Trait1;
42 pub const TRAIT1_GEN_REF: &'static Trait1Gen<u8> = &0u32 as &Trait1Gen<u8>;
43 pub const ID_CHAR: fn(char) -> char = id::<char>;
48 fn do_something(&self) {}
49 fn do_something_else(&self) {}
52 impl Trait2 for u32 {}
54 pub trait Trait2Gen<T> {
55 fn do_something(&self, x: T) -> T;
56 fn do_something_else(&self, x: T) -> T;
59 impl<T> Trait2Gen<T> for u32 {
60 fn do_something(&self, x: T) -> T { x }
61 fn do_something_else(&self, x: T) -> T { x }
64 // These are not referenced, so they do not produce trans-items
65 pub const TRAIT2_REF: &'static Trait2 = &0u32 as &Trait2;
66 pub const TRAIT2_GEN_REF: &'static Trait2Gen<u8> = &0u32 as &Trait2Gen<u8>;
67 pub const ID_I64: fn(i64) -> i64 = id::<i64>;
70 //~ TRANS_ITEM fn vtable_through_const::main[0] @@ vtable_through_const[External]
72 //~ TRANS_ITEM drop-glue i8 @@ vtable_through_const[Internal]
74 // Since Trait1::do_something() is instantiated via its default implementation,
75 // it is considered a generic and is instantiated here only because it is
76 // referenced in this module.
77 //~ TRANS_ITEM fn vtable_through_const::mod1[0]::Trait1[0]::do_something_else[0]<u32> @@ vtable_through_const[Internal]
79 // Although it is never used, Trait1::do_something_else() has to be
80 // instantiated locally here too, otherwise the <&u32 as &Trait1> vtable
81 // could not be fully constructed.
82 //~ TRANS_ITEM fn vtable_through_const::mod1[0]::Trait1[0]::do_something[0]<u32> @@ vtable_through_const[Internal]
83 mod1::TRAIT1_REF.do_something();
86 //~ TRANS_ITEM fn vtable_through_const::mod1[0]::{{impl}}[1]::do_something[0]<u8> @@ vtable_through_const[Internal]
87 //~ TRANS_ITEM fn vtable_through_const::mod1[0]::{{impl}}[1]::do_something_else[0]<u8> @@ vtable_through_const[Internal]
88 mod1::TRAIT1_GEN_REF.do_something(0u8);
90 //~ TRANS_ITEM fn vtable_through_const::mod1[0]::id[0]<char> @@ vtable_through_const[Internal]