Repository navigation
Conversation
The SIMD branch of `layout_of_uncached` read the array length from the unnormalized field type, so `#[repr(simd)] struct Foo([u8; C])` with `const C: usize = 16` saw an unevaluated alias const and returned `LayoutError::Unknown`. That ICEd in the mono ABI check (`fn_abi_of_instance(foo, []) failed: Layout(Unknown(Foo))`) and made `size_of::<Foo>()` fail const eval, while `[u8; 16]` worked. Normalize the field type first, reporting `NormalizationFailure` if that fails. Also add a `-Zno-codegen` regression test for rust-lang#149156, which was fixed by rust-lang#162057 but had no test. Fixes rust-lang#138008 Fixes rust-lang#149156 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For review before sending upstream to rust-lang/rust.
Fixes rust-lang#138008. Adds the missing regression test for rust-lang#149156.
Problem
The
#[repr(simd)]branch oflayout_of_uncached(compiler/rustc_ty_utils/src/layout.rs) matched on the unnormalized field type (.skip_norm_wip()). Withthe length is an unevaluated alias const, so
extract_const_valuehits theConstKind::Aliasarm and returnsLayoutError::Unknown(Foo). As a result:pub unsafe fn foo(a: Foo) {}ICEs in the mono ABI check:fn_abi_of_instance(foo, []) failed: Layout(Unknown(Foo))size_of::<Foo>()fails const eval (E0080)[u8; 16]works fineBisected to rust-lang#137852 (by matthiaskrgr on the issue).
Fix
Normalize the field type with
try_normalize_erasing_regions(cx.typing_env, ..)before inspecting it. A normalization failure becomesLayoutError::NormalizationFailure, the same way the pointee-metadata path handles it.Tests
tests/crashes/138008.rsmoved totests/ui/simd/repr-simd-const-item-len.rsasbuild-pass. It also assertssize_of::<Foo>() == 16in a const.tests/ui/limits/huge-arg-no-codegen.rs: the ICE: -Zno-codegen:ABI computation failure should lead to compilation failurerust-lang/rust#149156 repro under-Zno-codegen. It was fixed by Some cleanups around fatal errors and delayed bugs rust-lang/rust#162057 but had no test.Verified on a stage1 build:
tests/crashes,tests/ui/{abi,repr,const-generics,simd,layout,limits}: 1970 tests, 0 failures../x fmt --checkand./x test tidyare clean.🤖 Generated with Claude Code