]> git.proxmox.com Git - rustc.git/blob - src/doc/unstable-book/src/language-features/rustc-attrs.md
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / src / doc / unstable-book / src / language-features / rustc-attrs.md
1 # `rustc_attrs`
2
3 This feature has no tracking issue, and is therefore internal to
4 the compiler, not being intended for general use.
5
6 Note: `rustc_attrs` enables many rustc-internal attributes and this page
7 only discuss a few of them.
8
9 ------------------------
10
11 The `rustc_attrs` feature allows debugging rustc type layouts by using
12 `#[rustc_layout(...)]` to debug layout at compile time (it even works
13 with `cargo check`) as an alternative to `rustc -Z print-type-sizes`
14 that is way more verbose.
15
16 Options provided by `#[rustc_layout(...)]` are `debug`, `size`, `align`,
17 `abi`. Note that it only works on sized types without generics.
18
19 ## Examples
20
21 ```rust,ignore
22 #![feature(rustc_attrs)]
23
24 #[rustc_layout(abi, size)]
25 pub enum X {
26 Y(u8, u8, u8),
27 Z(isize),
28 }
29 ```
30
31 When that is compiled, the compiler will error with something like
32
33 ```text
34 error: abi: Aggregate { sized: true }
35 --> src/lib.rs:4:1
36 |
37 4 | / pub enum T {
38 5 | | Y(u8, u8, u8),
39 6 | | Z(isize),
40 7 | | }
41 | |_^
42
43 error: size: Size { raw: 16 }
44 --> src/lib.rs:4:1
45 |
46 4 | / pub enum T {
47 5 | | Y(u8, u8, u8),
48 6 | | Z(isize),
49 7 | | }
50 | |_^
51
52 error: aborting due to 2 previous errors
53 ```