1 // compile-flags: -Z print-type-sizes
4 // This file illustrates how generics are handled: types have to be
5 // monomorphized, in the MIR of the original function in which they
6 // occur, to have their size reported.
10 // In an ad-hoc attempt to avoid the injection of unwinding code
11 // (which clutters the output of `-Z print-type-sizes` with types from
12 // `unwind::libunwind`):
14 // * I am not using Default to build values because that seems to
15 // cause the injection of unwinding code. (Instead I just make `fn new`
18 // * Pair derive Copy to ensure that we don't inject
19 // unwinding code into generic uses of Pair when T itself is also
22 // (I suspect this reflect some naivety within the rust compiler
23 // itself; it should be checking for drop glue, i.e., a destructor
24 // somewhere in the monomorphized types. It should not matter whether
26 #[derive(Copy, Clone)]
33 fn new(a: T, d: T) -> Self {
41 #[derive(Copy, Clone)]
42 pub struct SevenBytes([u8; 7]);
43 pub struct FiftyBytes([u8; 50]);
48 fn new() -> Self { SevenBytes([0; 7]) }
52 fn new() -> Self { FiftyBytes([0; 50]) }
55 pub fn f1<T:Copy>(x: T) {
56 let _v: Pair<T> = Pair::new(x, x);
57 let _v2: Pair<FiftyBytes> =
58 Pair::new(FiftyBytes::new(), FiftyBytes::new());
62 fn start(_: isize, _: *const *const u8) -> isize {
63 let _b: Pair<u8> = Pair::new(0, 0);
64 let _s: Pair<SevenBytes> = Pair::new(SevenBytes::new(), SevenBytes::new());
65 let ref _z: ZeroSized = ZeroSized;
66 f1::<SevenBytes>(SevenBytes::new());