src/doc/unstable-book/src/language-features/rustc-attrs.md MARKDOWN 55 lines View on github.com → Search inside
1# `rustc_attrs`23This feature has no tracking issue, and is therefore internal to4the compiler, not being intended for general use.56Note: `rustc_attrs` enables many rustc-internal attributes and this page7only discuss a few of them.89------------------------1011The `rustc_attrs` feature allows debugging rustc type layouts by using12`#[rustc_dump_layout(...)]` to debug layout at compile time (it even works13with `cargo check`) as an alternative to `rustc -Z print-type-sizes`14that is way more verbose.1516Options provided by `#[rustc_dump_layout(...)]` are `backend_repr`, `align`,17`debug`, `homogeneous_aggregate` and `size`.18Note that it only works on sized types without generics.1920## Examples2122```rust,compile_fail23#![feature(rustc_attrs)]2425#[rustc_dump_layout(backend_repr, size)]26pub enum X {27    Y(u8, u8, u8),28    Z(isize),29}30```3132When that is compiled, the compiler will error with something like3334```text35error: backend_repr: Aggregate { sized: true }36 --> src/lib.rs:4:137  |384 | / pub enum T {395 | |     Y(u8, u8, u8),406 | |     Z(isize),417 | | }42  | |_^4344error: size: Size { raw: 16 }45 --> src/lib.rs:4:146  |474 | / pub enum T {485 | |     Y(u8, u8, u8),496 | |     Z(isize),507 | | }51  | |_^5253error: aborting due to 2 previous errors54```

Findings

✓ No findings reported for this file.

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.