Commit 7f1b2c3
committed
Fix ICE in pointer layout for DSTs with bogus Sized impls
A bogus `impl<T: ?Sized> Sized for T {}` (rejected as E0322) was
processed by the new trait solver (`-Znext-solver=globally`), making
DSTs like `[T]` appear sized. This caused `*const [T]` to receive a
thin-pointer (Scalar) layout instead of a fat-pointer (ScalarPair)
layout. When const evaluation then performed an array-to-slice unsizing
coercion and tried to write a ScalarPair value to a Scalar-layout place,
it triggered an ICE:
"invalid immediate for given destination place: value ScalarPair(...)
does not match ABI Scalar(...)"
The fix adds a structural cross-check in the pointer layout computation:
after `is_sized` returns true, we verify via `struct_tail_for_codegen`
(which is purely structural and unaffected by bogus trait impls) that
the pointee tail is not a known DST kind (Slice/Str/Dynamic). If it is,
we skip the thin-pointer early return and fall through to compute the
correct fat-pointer layout.1 parent a72e2a7 commit 7f1b2c3
3 files changed
Lines changed: 56 additions & 1 deletion
File tree
- compiler/rustc_ty_utils/src
- tests/ui/traits/next-solver
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
414 | 414 | | |
415 | 415 | | |
416 | 416 | | |
417 | | - | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
418 | 432 | | |
419 | 433 | | |
420 | 434 | | |
| |||
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
0 commit comments