File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -274,3 +274,62 @@ try`. This is helpful when you want to examine the resulting build of a PR
274274without doing the build yourself.
275275
276276[rtim]: https://github.com/kennytm/rustup-toolchain-install-master
277+
278+ ## Debugging type layouts
279+
280+ The (permanently) unstable `#[rustc_layout]` attribute can be used to dump
281+ the [`Layout`] of the type it is attached to. For example:
282+
283+ ```rust
284+ #![feature(rustc_attrs)]
285+
286+ #[rustc_layout(debug)]
287+ type T<' a> = & ' a u32;
288+ ```
289+
290+ Will emit the following:
291+
292+ ```text
293+ error: layout_of(&' a u32) = Layout {
294+ fields: Primitive,
295+ variants: Single {
296+ index: 0,
297+ },
298+ abi: Scalar(
299+ Scalar {
300+ value: Pointer,
301+ valid_range: 1..=18446744073709551615,
302+ },
303+ ),
304+ largest_niche: Some(
305+ Niche {
306+ offset: Size {
307+ raw: 0,
308+ },
309+ scalar: Scalar {
310+ value: Pointer,
311+ valid_range: 1..=18446744073709551615,
312+ },
313+ },
314+ ),
315+ align: AbiAndPrefAlign {
316+ abi: Align {
317+ pow2: 3,
318+ },
319+ pref: Align {
320+ pow2: 3,
321+ },
322+ },
323+ size: Size {
324+ raw: 8,
325+ },
326+ }
327+ --> src/lib.rs:4:1
328+ |
329+ 4 | type T< ' a> = &' a u32;
330+ | ^^^^^^^^^^^^^^^^^^^^^
331+
332+ error: aborting due to previous error
333+ ` ` `
334+
335+ [` Layout` ]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/abi/struct.Layout.html
You can’t perform that action at this time.
0 commit comments