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 // 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).
16 // The test tries to exercise as many different paths into symbol name
17 // generation as possible:
19 // - regular functions
20 // - generic functions
24 // - enum variant constructors
25 // - tuple struct constructors
28 // - Trait object shims
31 #![allow(dead_code, warnings)]
33 extern crate reproducible_build_aux;
35 static STATIC: i32 = 1234;
37 pub struct Struct<T1, T2> {
42 fn regular_fn(_: i32) {}
44 fn generic_fn<T1, T2>() {}
46 impl<T1, T2> Drop for Struct<T1, T2> {
56 struct TupleStruct(i8, i16, i32, i64);
66 impl Trait<i32, u64> for u64 {
70 impl reproducible_build_aux::Trait<char, String> for TupleStruct {
76 generic_fn::<u32, char>();
77 generic_fn::<char, Struct<u32, u64>>();
78 generic_fn::<Struct<u64, u32>, reproducible_build_aux::Struct<u32, u64>>();
80 let dropped = Struct {
85 let _ = Enum::Variant1;
86 let _ = Enum::Variant2(0);
87 let _ = Enum::Variant3 { x: 0 };
88 let _ = TupleStruct(1, 2, 3, 4);
94 fn inner<F: Fn(i32) -> i32>(f: F) -> i32 {
98 println!("{}", inner(closure));
100 let object_shim: &Trait<i32, u64> = &0u64;
103 fn with_fn_once_adapter<F: FnOnce(i32)>(f: F) {
107 with_fn_once_adapter(|_:i32| { });
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>>();
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);
120 let object_shim: &reproducible_build_aux::Trait<char, String> = &TupleStruct(0, 1, 2, 3);
123 let pointer_shim: &Fn(i32) = ®ular_fn;
125 TupleStruct(1, 2, 3, 4).bar();