]> git.lizzy.rs Git - rust.git/blob - src/test/codegen-units/unused-traits-and-generics.rs
Implement the translation item collector.
[rust.git] / src / test / codegen-units / unused-traits-and-generics.rs
1 // Copyright 2012-2015 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 // compile-flags:-Zprint-trans-items=eager
13
14 #![crate_type="lib"]
15 #![deny(dead_code)]
16
17 // This test asserts that no codegen items are generated for generic items that
18 // are never instantiated in the local crate.
19
20 pub trait Trait {
21     fn foo() {}
22     fn bar(&self) {}
23 }
24
25 pub fn foo<T: Copy>(x: T) -> (T, T) {
26     (x, x)
27 }
28
29 pub struct Struct<T> {
30     x: T
31 }
32
33 impl<T> Struct<T> {
34     pub fn foo(self) -> T {
35         self.x
36     }
37
38     pub fn bar() {}
39 }
40
41 pub enum Enum<T> {
42     A(T),
43     B { x: T }
44 }
45
46 impl<T> Enum<T> {
47     pub fn foo(self) -> T {
48         match self {
49             Enum::A(x) => x,
50             Enum::B { x } => x,
51         }
52     }
53
54     pub fn bar() {}
55 }
56
57 pub struct TupleStruct<T>(T);
58
59 impl<T> TupleStruct<T> {
60     pub fn foo(self) -> T {
61         self.0
62     }
63
64     pub fn bar() {}
65 }
66
67 pub type Pair<T> = (T, T);
68
69 pub struct NonGeneric {
70     x: i32
71 }
72
73 impl NonGeneric {
74     pub fn foo(self) -> i32 {
75         self.x
76     }
77
78     pub fn generic_foo<T>(&self, x: T) -> (T, i32) {
79         (x, self.x)
80     }
81
82     pub fn generic_bar<T: Copy>(x: T) -> (T, T) {
83         (x, x)
84     }
85 }
86
87 // Only the non-generic methods should be instantiated:
88 //~ TRANS_ITEM fn unused_traits_and_generics::NonGeneric[0]::foo[0]
89 //~ TRANS_ITEM drop-glue i8