From f772587aba7b2be9a2fa708a26ba2605e32148ff Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Sat, 27 Jun 2020 13:09:06 +0800 Subject: [PATCH 1/4] Add unstable docs for rustc_attrs --- .../src/language-features/rustc-attrs.md | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/doc/unstable-book/src/language-features/rustc-attrs.md 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 0000000000000..500ae61b1dd08 --- /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 +``` From 725918f17e9a2c1e8a0ffec658d1363681f768bd Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Sun, 28 Jun 2020 00:23:37 +0800 Subject: [PATCH 2/4] Update src/doc/unstable-book/src/language-features/rustc-attrs.md Co-authored-by: Ralf Jung --- src/doc/unstable-book/src/language-features/rustc-attrs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/unstable-book/src/language-features/rustc-attrs.md b/src/doc/unstable-book/src/language-features/rustc-attrs.md index 500ae61b1dd08..01450c8fb1f9b 100644 --- a/src/doc/unstable-book/src/language-features/rustc-attrs.md +++ b/src/doc/unstable-book/src/language-features/rustc-attrs.md @@ -1,6 +1,6 @@ # `rustc_attrs` -This feature has no tracking issue, and is therefore likely internal to +This feature has no tracking issue, and is therefore internal to the compiler, not being intended for general use. ------------------------ From 0e6f1093be08949b6ac4ba3d92ad4e97d0137dc5 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Sun, 28 Jun 2020 21:47:58 +0800 Subject: [PATCH 3/4] Add preamable on rustc-attrs doc discussion --- src/doc/unstable-book/src/language-features/rustc-attrs.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/doc/unstable-book/src/language-features/rustc-attrs.md b/src/doc/unstable-book/src/language-features/rustc-attrs.md index 01450c8fb1f9b..ad96aaf8281d6 100644 --- a/src/doc/unstable-book/src/language-features/rustc-attrs.md +++ b/src/doc/unstable-book/src/language-features/rustc-attrs.md @@ -3,6 +3,9 @@ This feature has no tracking issue, and is therefore internal to the compiler, not being intended for general use. +Note: `rustc_attrs` enables many rustc-internal attributes and this page +only discuss a few of them. + ------------------------ The `rustc_attrs` feature allows debugging rustc type layouts by using From 49b4804d291bc8cc93e7b4b8c24f344aa3e3f484 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Mon, 29 Jun 2020 10:56:10 +0800 Subject: [PATCH 4/4] Ignore example compile in rustc-attrs doc --- src/doc/unstable-book/src/language-features/rustc-attrs.md | 4 ++-- 1 file changed, 2 insertions(+), 2 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 index ad96aaf8281d6..2967200faf80d 100644 --- a/src/doc/unstable-book/src/language-features/rustc-attrs.md +++ b/src/doc/unstable-book/src/language-features/rustc-attrs.md @@ -18,7 +18,7 @@ Note that it only work best with sized type without generics. ## Examples -```rust +```rust,ignore #![feature(rustc_attrs)] #[rustc_layout(abi, size)] @@ -30,7 +30,7 @@ pub enum X { When that is compiled, the compiler will error with something like -``` +```text error: abi: Aggregate { sized: true } --> src/lib.rs:4:1 |