]> git.lizzy.rs Git - rust.git/blob - src/test/codegen-units/item-collection/unused-traits-and-generics.rs
rustdoc-json: Make the `fns/generics.rs` test much more robust
[rust.git] / src / test / codegen-units / item-collection / unused-traits-and-generics.rs
1 // compile-flags:-Zprint-mono-items=eager
2
3 #![crate_type="lib"]
4 #![deny(dead_code)]
5
6 // This test asserts that no codegen items are generated for generic items that
7 // are never instantiated in the local crate.
8
9 pub trait Trait {
10     fn foo() {}
11     fn bar(&self) {}
12 }
13
14 pub fn foo<T: Copy>(x: T) -> (T, T) {
15     (x, x)
16 }
17
18 pub struct Struct<T> {
19     x: T
20 }
21
22 impl<T> Struct<T> {
23     pub fn foo(self) -> T {
24         self.x
25     }
26
27     pub fn bar() {}
28 }
29
30 pub enum Enum<T> {
31     A(T),
32     B { x: T }
33 }
34
35 impl<T> Enum<T> {
36     pub fn foo(self) -> T {
37         match self {
38             Enum::A(x) => x,
39             Enum::B { x } => x,
40         }
41     }
42
43     pub fn bar() {}
44 }
45
46 pub struct TupleStruct<T>(T);
47
48 impl<T> TupleStruct<T> {
49     pub fn foo(self) -> T {
50         self.0
51     }
52
53     pub fn bar() {}
54 }
55
56 pub type Pair<T> = (T, T);
57
58 pub struct NonGeneric {
59     x: i32
60 }
61
62 impl NonGeneric {
63     pub fn foo(self) -> i32 {
64         self.x
65     }
66
67     pub fn generic_foo<T>(&self, x: T) -> (T, i32) {
68         (x, self.x)
69     }
70
71     pub fn generic_bar<T: Copy>(x: T) -> (T, T) {
72         (x, x)
73     }
74 }
75
76 // Only the non-generic methods should be instantiated:
77 //~ MONO_ITEM fn NonGeneric::foo