]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/print_type_sizes/generics.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.
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 // compile-flags: -Z print-type-sizes
13 // This file illustrates how generics are handled: types have to be
14 // monomorphized, in the MIR of the original function in which they
15 // occur, to have their size reported.
17 // In an ad-hoc attempt to avoid the injection of unwinding code
18 // (which clutters the output of `-Z print-type-sizes` with types from
19 // `unwind::libunwind`):
21 // * I am not using Default to build values because that seems to
22 // cause the injection of unwinding code. (Instead I just make `fn new`
25 // * Pair derive Copy to ensure that we don't inject
26 // unwinding code into generic uses of Pair when T itself is also
29 // (I suspect this reflect some naivety within the rust compiler
30 // itself; it should be checking for drop glue, i.e. a destructor
31 // somewhere in the monomorphized types. It should not matter whether
33 #[derive(Copy, Clone)]
40 fn new(a
: T
, d
: T
) -> Self {
48 #[derive(Copy, Clone)]
49 pub struct SevenBytes([u8; 7]);
50 pub struct FiftyBytes([u8; 50]);
55 fn new() -> Self { SevenBytes([0; 7]) }
59 fn new() -> Self { FiftyBytes([0; 50]) }
62 pub fn f1
<T
:Copy
>(x
: T
) {
63 let _v
: Pair
<T
> = Pair
::new(x
, x
);
64 let _v2
: Pair
<FiftyBytes
> =
65 Pair
::new(FiftyBytes
::new(), FiftyBytes
::new());
69 let _b
: Pair
<u8> = Pair
::new(0, 0);
70 let _s
: Pair
<SevenBytes
> = Pair
::new(SevenBytes
::new(), SevenBytes
::new());
71 let _z
: ZeroSized
= ZeroSized
;
72 f1
::<SevenBytes
>(SevenBytes
::new());