]> git.lizzy.rs Git - rust.git/blob - src/test/rustdoc/type-layout.rs
Rollup merge of #91699 - jsha:webkit-appearance-search-input, r=GuillaumeGomez
[rust.git] / src / test / rustdoc / type-layout.rs
1 // compile-flags: --show-type-layout -Z unstable-options
2
3 // @has type_layout/struct.Foo.html 'Size: '
4 // @has - ' bytes'
5 pub struct Foo {
6     pub a: usize,
7     b: Vec<String>,
8 }
9
10 // @has type_layout/enum.Bar.html 'Size: '
11 // @has - ' bytes'
12 pub enum Bar<'a> {
13     A(String),
14     B(&'a str, (std::collections::HashMap<String, usize>, Foo)),
15 }
16
17 // @has type_layout/union.Baz.html 'Size: '
18 // @has - ' bytes'
19 pub union Baz {
20     a: &'static str,
21     b: usize,
22     c: &'static [u8],
23 }
24
25 // @has type_layout/struct.X.html 'Size: '
26 // @has - ' bytes'
27 pub struct X(usize);
28
29 // @has type_layout/struct.Y.html 'Size: '
30 // @has - '1 byte'
31 // @!has - ' bytes'
32 pub struct Y(u8);
33
34 // @has type_layout/struct.Z.html 'Size: '
35 // @has - '0 bytes'
36 pub struct Z;
37
38 // We can't compute layout for generic types.
39 // @has type_layout/struct.Generic.html 'Unable to compute type layout, possibly due to this type having generic parameters'
40 // @!has - 'Size: '
41 pub struct Generic<T>(T);
42
43 // We *can*, however, compute layout for types that are only generic over lifetimes,
44 // because lifetimes are a type-system construct.
45 // @has type_layout/struct.GenericLifetimes.html 'Size: '
46 // @has - ' bytes'
47 pub struct GenericLifetimes<'a>(&'a str);
48
49 // @has type_layout/struct.Unsized.html 'Size: '
50 // @has - '(unsized)'
51 pub struct Unsized([u8]);
52
53 // @has type_layout/type.TypeAlias.html 'Size: '
54 // @has - ' bytes'
55 pub type TypeAlias = X;
56
57 // @has type_layout/type.GenericTypeAlias.html 'Size: '
58 // @has - '8 bytes'
59 pub type GenericTypeAlias = (Generic<(u32, ())>, Generic<u32>);
60
61 // Regression test for the rustdoc equivalent of #85103.
62 // @has type_layout/type.Edges.html 'Encountered an error during type layout; the type failed to be normalized.'
63 pub type Edges<'a, E> = std::borrow::Cow<'a, [E]>;
64
65 // @!has type_layout/trait.MyTrait.html 'Size: '
66 pub trait MyTrait {}
67
68 // @has type_layout/enum.Variants.html 'Size: '
69 // @has - '2 bytes'
70 // @has - '<code>A</code>: 0 bytes'
71 // @has - '<code>B</code>: 1 byte'
72 pub enum Variants {
73     A,
74     B(u8),
75 }
76
77 // @has type_layout/enum.WithNiche.html 'Size: '
78 // @has - //p '4 bytes'
79 // @has - '<code>None</code>: 0 bytes'
80 // @has - '<code>Some</code>: 4 bytes'
81 pub enum WithNiche {
82     None,
83     Some(std::num::NonZeroU32),
84 }