1
Fork 0
rust/compiler/rustc_hir_analysis/src/check
bors cb80ff132a Auto merge of #113245 - lukas-code:unsizing-sanity-check, r=the8472
sanity check field offsets in unsizeable structs

As promised in https://github.com/rust-lang/rust/pull/112062#issuecomment-1567494994, this PR extends the layout sanity checks to ensure that structs fields don't move around when unsizing and prevent issues like https://github.com/rust-lang/rust/issues/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`
2023-07-07 15:42:29 +00:00
..
check.rs Move TyCtxt::mk_x to Ty::new_x where applicable 2023-07-05 20:27:07 +01:00
compare_impl_item.rs Do not assert >1 RPITITs on collect_return_position_impl_trait_in_trait_tys 2023-07-06 17:07:11 -03:00
dropck.rs Rollup merge of #112060 - lcnr:early-binder, r=jackh726 2023-05-30 12:57:40 +02:00
intrinsic.rs Move TyCtxt::mk_x to Ty::new_x where applicable 2023-07-05 20:27:07 +01:00
intrinsicck.rs Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
mod.rs Migrate predicates_of and caller_bounds to Clause 2023-06-26 23:12:03 +00:00
region.rs Separate AnonConst from ConstBlock in HIR. 2023-06-02 21:25:18 +00:00
wfcheck.rs add helper methods for accessing struct tail 2023-07-06 13:15:05 +00:00