File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
src/doc/unstable-book/src/language-features Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments