diff options
| author | Ivan Tham <pickfire@riseup.net> | 2020-06-27 13:09:06 +0800 |
|---|---|---|
| committer | Ivan Tham <pickfire@riseup.net> | 2020-06-27 15:01:57 +0800 |
| commit | f772587aba7b2be9a2fa708a26ba2605e32148ff (patch) | |
| tree | d359e74c1b461589acdbb84e6cb2f86791f985e3 | |
| parent | dda8a7fde92a0be3f18b863bf35bebf195f8ed5c (diff) | |
| download | rust-f772587aba7b2be9a2fa708a26ba2605e32148ff.tar.gz rust-f772587aba7b2be9a2fa708a26ba2605e32148ff.zip | |
Add unstable docs for rustc_attrs
| -rw-r--r-- | src/doc/unstable-book/src/language-features/rustc-attrs.md | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/doc/unstable-book/src/language-features/rustc-attrs.md b/src/doc/unstable-book/src/language-features/rustc-attrs.md new file mode 100644 index 00000000000..500ae61b1dd --- /dev/null +++ b/src/doc/unstable-book/src/language-features/rustc-attrs.md @@ -0,0 +1,50 @@ +# `rustc_attrs` + +This feature has no tracking issue, and is therefore likely internal to +the compiler, not being intended for general use. + +------------------------ + +The `rustc_attrs` feature allows debugging rustc type layouts by using +`#[rustc_layout(...)]` to debug layout at compile time (it even works +with `cargo check`) as an alternative to `rustc -Z print-type-sizes` +that is way more verbose. + +Options provided by `#[rustc_layout(...)]` are `debug`, `size`, `abi`. +Note that it only work best with sized type without generics. + +## Examples + +```rust +#![feature(rustc_attrs)] + +#[rustc_layout(abi, size)] +pub enum X { + Y(u8, u8, u8), + Z(isize), +} +``` + +When that is compiled, the compiler will error with something like + +``` +error: abi: Aggregate { sized: true } + --> src/lib.rs:4:1 + | +4 | / pub enum T { +5 | | Y(u8, u8, u8), +6 | | Z(isize), +7 | | } + | |_^ + +error: size: Size { raw: 16 } + --> src/lib.rs:4:1 + | +4 | / pub enum T { +5 | | Y(u8, u8, u8), +6 | | Z(isize), +7 | | } + | |_^ + +error: aborting due to 2 previous errors +``` |
