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