]> git.lizzy.rs Git - rust.git/blob - src/test/run-make-fulldeps/reproducible-build/reproducible-build.rs
a040c0f858d78d85a566c3c2d03a749240fd4023
[rust.git] / src / test / run-make-fulldeps / reproducible-build / reproducible-build.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 // This test case makes sure that two identical invocations of the compiler
12 // (i.e. same code base, same compile-flags, same compiler-versions, etc.)
13 // produce the same output. In the past, symbol names of monomorphized functions
14 // were not deterministic (which we want to avoid).
15 //
16 // The test tries to exercise as many different paths into symbol name
17 // generation as possible:
18 //
19 // - regular functions
20 // - generic functions
21 // - methods
22 // - statics
23 // - closures
24 // - enum variant constructors
25 // - tuple struct constructors
26 // - drop glue
27 // - FnOnce adapters
28 // - Trait object shims
29 // - Fn Pointer shims
30
31 #![allow(dead_code, warnings)]
32
33 extern crate reproducible_build_aux;
34
35 static STATIC: i32 = 1234;
36
37 pub struct Struct<T1, T2> {
38     x: T1,
39     y: T2,
40 }
41
42 fn regular_fn(_: i32) {}
43
44 fn generic_fn<T1, T2>() {}
45
46 impl<T1, T2> Drop for Struct<T1, T2> {
47     fn drop(&mut self) {}
48 }
49
50 pub enum Enum {
51     Variant1,
52     Variant2(u32),
53     Variant3 { x: u32 }
54 }
55
56 struct TupleStruct(i8, i16, i32, i64);
57
58 impl TupleStruct {
59     pub fn bar(&self) {}
60 }
61
62 trait Trait<T1, T2> {
63     fn foo(&self);
64 }
65
66 impl Trait<i32, u64> for u64 {
67     fn foo(&self) {}
68 }
69
70 impl reproducible_build_aux::Trait<char, String> for TupleStruct {
71     fn foo(&self) {}
72 }
73
74 fn main() {
75     regular_fn(STATIC);
76     generic_fn::<u32, char>();
77     generic_fn::<char, Struct<u32, u64>>();
78     generic_fn::<Struct<u64, u32>, reproducible_build_aux::Struct<u32, u64>>();
79
80     let dropped = Struct {
81         x: "",
82         y: 'a',
83     };
84
85     let _ = Enum::Variant1;
86     let _ = Enum::Variant2(0);
87     let _ = Enum::Variant3 { x: 0 };
88     let _ = TupleStruct(1, 2, 3, 4);
89
90     let closure  = |x| {
91         x + 1i32
92     };
93
94     fn inner<F: Fn(i32) -> i32>(f: F) -> i32 {
95         f(STATIC)
96     }
97
98     println!("{}", inner(closure));
99
100     let object_shim: &Trait<i32, u64> = &0u64;
101     object_shim.foo();
102
103     fn with_fn_once_adapter<F: FnOnce(i32)>(f: F) {
104         f(0);
105     }
106
107     with_fn_once_adapter(|_:i32| { });
108
109     reproducible_build_aux::regular_fn(STATIC);
110     reproducible_build_aux::generic_fn::<u32, char>();
111     reproducible_build_aux::generic_fn::<char, Struct<u32, u64>>();
112     reproducible_build_aux::generic_fn::<Struct<u64, u32>,
113                                          reproducible_build_aux::Struct<u32, u64>>();
114
115     let _ = reproducible_build_aux::Enum::Variant1;
116     let _ = reproducible_build_aux::Enum::Variant2(0);
117     let _ = reproducible_build_aux::Enum::Variant3 { x: 0 };
118     let _ = reproducible_build_aux::TupleStruct(1, 2, 3, 4);
119
120     let object_shim: &reproducible_build_aux::Trait<char, String> = &TupleStruct(0, 1, 2, 3);
121     object_shim.foo();
122
123     let pointer_shim: &Fn(i32) = &regular_fn;
124
125     TupleStruct(1, 2, 3, 4).bar();
126 }