1 // compile-flags: -Z print-type-sizes
4 // ^-- needed because `--pass check` does not emit the output needed.
5 // FIXME: consider using an attribute instead of side-effects.
7 // This file illustrates how generics are handled: types have to be
8 // monomorphized, in the MIR of the original function in which they
9 // occur, to have their size reported.
13 // In an ad-hoc attempt to avoid the injection of unwinding code
14 // (which clutters the output of `-Z print-type-sizes` with types from
15 // `unwind::libunwind`):
17 // * I am not using Default to build values because that seems to
18 // cause the injection of unwinding code. (Instead I just make `fn new`
21 // * Pair derive Copy to ensure that we don't inject
22 // unwinding code into generic uses of Pair when T itself is also
25 // (I suspect this reflect some naivety within the rust compiler
26 // itself; it should be checking for drop glue, i.e., a destructor
27 // somewhere in the monomorphized types. It should not matter whether
29 #[derive(Copy, Clone)]
36 fn new(a: T, d: T) -> Self {
44 #[derive(Copy, Clone)]
45 pub struct SevenBytes([u8; 7]);
46 pub struct FiftyBytes([u8; 50]);
51 fn new() -> Self { SevenBytes([0; 7]) }
55 fn new() -> Self { FiftyBytes([0; 50]) }
58 pub fn f1<T:Copy>(x: T) {
59 let _v: Pair<T> = Pair::new(x, x);
60 let _v2: Pair<FiftyBytes> =
61 Pair::new(FiftyBytes::new(), FiftyBytes::new());
65 fn start(_: isize, _: *const *const u8) -> isize {
66 let _b: Pair<u8> = Pair::new(0, 0);
67 let _s: Pair<SevenBytes> = Pair::new(SevenBytes::new(), SevenBytes::new());
68 let ref _z: ZeroSized = ZeroSized;
69 f1::<SevenBytes>(SevenBytes::new());