Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unstable docs for rustc_attrs #73787

Merged
merged 4 commits into from
Jul 6, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/doc/unstable-book/src/language-features/rustc-attrs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# `rustc_attrs`

This feature has no tracking issue, and is therefore likely internal to
pickfire marked this conversation as resolved.
Show resolved Hide resolved
the compiler, not being intended for general use.

------------------------

The `rustc_attrs` feature allows debugging rustc type layouts by using
pickfire marked this conversation as resolved.
Show resolved Hide resolved
`#[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

```
pickfire marked this conversation as resolved.
Show resolved Hide resolved
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
```