]> git.lizzy.rs Git - rust.git/blob - tests/ui/print_type_sizes/generics.rs
Rollup merge of #106766 - GuillaumeGomez:rm-stripper-dead-code, r=notriddle
[rust.git] / tests / ui / print_type_sizes / generics.rs
1 // compile-flags: -Z print-type-sizes --crate-type=lib
2 // build-pass
3 // ignore-pass
4 // ^-- needed because `--pass check` does not emit the output needed.
5 //     FIXME: consider using an attribute instead of side-effects.
6
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.
10
11 #[derive(Copy, Clone)]
12 pub struct Pair<T> {
13     _car: T,
14     _cdr: T,
15 }
16
17 impl<T> Pair<T> {
18     fn new(a: T, d: T) -> Self {
19         Pair {
20             _car: a,
21             _cdr: d,
22         }
23     }
24 }
25
26 #[derive(Copy, Clone)]
27 pub struct SevenBytes([u8; 7]);
28 pub struct FiftyBytes([u8; 50]);
29
30 pub struct ZeroSized;
31
32 impl SevenBytes {
33     fn new() -> Self { SevenBytes([0; 7]) }
34 }
35
36 impl FiftyBytes {
37     fn new() -> Self { FiftyBytes([0; 50]) }
38 }
39
40 pub fn f1<T:Copy>(x: T) {
41     let _v: Pair<T> = Pair::new(x, x);
42     let _v2: Pair<FiftyBytes> =
43         Pair::new(FiftyBytes::new(), FiftyBytes::new());
44 }
45
46 pub fn start() {
47     let _b: Pair<u8> = Pair::new(0, 0);
48     let _s: Pair<SevenBytes> = Pair::new(SevenBytes::new(), SevenBytes::new());
49     let ref _z: ZeroSized = ZeroSized;
50     f1::<SevenBytes>(SevenBytes::new());
51 }