Skip to content

Commit

Permalink
Auto merge of #113245 - lukas-code:unsizing-sanity-check, r=the8472
Browse files Browse the repository at this point in the history
sanity check field offsets in unsizeable structs

As promised in rust-lang/rust#112062 (comment), this PR extends the layout sanity checks to ensure that structs fields don't move around when unsizing and prevent issues like rust-lang/rust#112048 in the future. Like most other layout sanity checks, this only runs on compilers with debug assertions enabled.

Here is how it looks when it fails:
```text
error: internal compiler error: compiler/rustc_ty_utils/src/layout.rs:533:21: unsizing GcNode<std::boxed::Box<i32>> changed field order!
                                Layout { size: Size(32 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes) }, abi: Aggregate { sized: true }, fields: Arbitrary { offsets: [Size(0 bytes), Size(8 bytes), Size(24 bytes)], memory_index: [0, 1, 2] }, largest_niche: Some(Niche { offset: Size(24 bytes), value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }), variants: Single { index: 0 } }
                                Layout { size: Size(24 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes) }, abi: Aggregate { sized: false }, fields: Arbitrary { offsets: [Size(16 bytes), Size(0 bytes), Size(24 bytes)], memory_index: [1, 0, 2] }, largest_niche: None, variants: Single { index: 0 } }
```

r? `@the8472`
  • Loading branch information
bors committed Jul 7, 2023
2 parents ba9e8be + 43cf79d commit 5df3bbe
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit 5df3bbe

Please sign in to comment.