]> git.proxmox.com Git - rustc.git/blob - src/test/codegen-units/partitioning/methods-are-with-self-type.rs
New upstream version 1.12.0+dfsg1
[rustc.git] / src / test / codegen-units / partitioning / methods-are-with-self-type.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 // Currently, all generic functions are instantiated in each codegen unit that
12 // uses them, even those not marked with #[inline], so this test does not make
13 // much sense at the moment.
14 // ignore-test
15
16 // ignore-tidy-linelength
17 // We specify -Z incremental here because we want to test the partitioning for
18 // incremental compilation
19 // compile-flags:-Zprint-trans-items=lazy -Zincremental=tmp/partitioning-tests/methods-are-with-self-type
20
21 #![allow(dead_code)]
22
23 struct SomeType;
24
25 struct SomeGenericType<T1, T2>(T1, T2);
26
27 mod mod1 {
28 use super::{SomeType, SomeGenericType};
29
30 // Even though the impl is in `mod1`, the methods should end up in the
31 // parent module, since that is where their self-type is.
32 impl SomeType {
33 //~ TRANS_ITEM fn methods_are_with_self_type::mod1[0]::{{impl}}[0]::method[0] @@ methods_are_with_self_type[External]
34 fn method(&self) {}
35
36 //~ TRANS_ITEM fn methods_are_with_self_type::mod1[0]::{{impl}}[0]::associated_fn[0] @@ methods_are_with_self_type[External]
37 fn associated_fn() {}
38 }
39
40 impl<T1, T2> SomeGenericType<T1, T2> {
41 pub fn method(&self) {}
42 pub fn associated_fn(_: T1, _: T2) {}
43 }
44 }
45
46 trait Trait {
47 fn foo(&self);
48 fn default(&self) {}
49 }
50
51 // We provide an implementation of `Trait` for all types. The corresponding
52 // monomorphizations should end up in whichever module the concrete `T` is.
53 impl<T> Trait for T
54 {
55 fn foo(&self) {}
56 }
57
58 mod type1 {
59 pub struct Struct;
60 }
61
62 mod type2 {
63 pub struct Struct;
64 }
65
66 //~ TRANS_ITEM fn methods_are_with_self_type::main[0]
67 fn main()
68 {
69 //~ TRANS_ITEM fn methods_are_with_self_type::mod1[0]::{{impl}}[1]::method[0]<u32, u64> @@ methods_are_with_self_type.volatile[WeakODR]
70 SomeGenericType(0u32, 0u64).method();
71 //~ TRANS_ITEM fn methods_are_with_self_type::mod1[0]::{{impl}}[1]::associated_fn[0]<char, &str> @@ methods_are_with_self_type.volatile[WeakODR]
72 SomeGenericType::associated_fn('c', "&str");
73
74 //~ TRANS_ITEM fn methods_are_with_self_type::{{impl}}[0]::foo[0]<methods_are_with_self_type::type1[0]::Struct[0]> @@ methods_are_with_self_type-type1.volatile[WeakODR]
75 type1::Struct.foo();
76 //~ TRANS_ITEM fn methods_are_with_self_type::{{impl}}[0]::foo[0]<methods_are_with_self_type::type2[0]::Struct[0]> @@ methods_are_with_self_type-type2.volatile[WeakODR]
77 type2::Struct.foo();
78
79 //~ TRANS_ITEM fn methods_are_with_self_type::Trait[0]::default[0]<methods_are_with_self_type::type1[0]::Struct[0]> @@ methods_are_with_self_type-type1.volatile[WeakODR]
80 type1::Struct.default();
81 //~ TRANS_ITEM fn methods_are_with_self_type::Trait[0]::default[0]<methods_are_with_self_type::type2[0]::Struct[0]> @@ methods_are_with_self_type-type2.volatile[WeakODR]
82 type2::Struct.default();
83 }
84
85 //~ TRANS_ITEM drop-glue i8