Skip to content

Commit f772587

Browse files
committed
Add unstable docs for rustc_attrs
1 parent dda8a7f commit f772587

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# `rustc_attrs`
2+
3+
This feature has no tracking issue, and is therefore likely internal to
4+
the compiler, not being intended for general use.
5+
6+
------------------------
7+
8+
The `rustc_attrs` feature allows debugging rustc type layouts by using
9+
`#[rustc_layout(...)]` to debug layout at compile time (it even works
10+
with `cargo check`) as an alternative to `rustc -Z print-type-sizes`
11+
that is way more verbose.
12+
13+
Options provided by `#[rustc_layout(...)]` are `debug`, `size`, `abi`.
14+
Note that it only work best with sized type without generics.
15+
16+
## Examples
17+
18+
```rust
19+
#![feature(rustc_attrs)]
20+
21+
#[rustc_layout(abi, size)]
22+
pub enum X {
23+
Y(u8, u8, u8),
24+
Z(isize),
25+
}
26+
```
27+
28+
When that is compiled, the compiler will error with something like
29+
30+
```
31+
error: abi: Aggregate { sized: true }
32+
--> src/lib.rs:4:1
33+
|
34+
4 | / pub enum T {
35+
5 | | Y(u8, u8, u8),
36+
6 | | Z(isize),
37+
7 | | }
38+
| |_^
39+
40+
error: size: Size { raw: 16 }
41+
--> src/lib.rs:4:1
42+
|
43+
4 | / pub enum T {
44+
5 | | Y(u8, u8, u8),
45+
6 | | Z(isize),
46+
7 | | }
47+
| |_^
48+
49+
error: aborting due to 2 previous errors
50+
```

0 commit comments

Comments
 (0)