Skip to content

Commit e2ae88d

Browse files
authored
Rollup merge of #73787 - pickfire:rustc-attrs, r=RalfJung
Add unstable docs for rustc_attrs r? @RalfJung
2 parents 5311daa + 49b4804 commit e2ae88d

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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`, `abi`.
17+
Note that it only work best with sized type 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+
```

0 commit comments

Comments
 (0)