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