Fix ICE when using zero-length SIMD type in extern static#151495
Merged
rust-bors[bot] merged 1 commit intoJan 23, 2026
Conversation
Collaborator
|
rustbot has assigned @JonathanBrouwer. Use |
|
|
||
| unsafe extern "C" { | ||
| static VAR: Simd<u8, 0>; | ||
| //~^ ERROR the SIMD type `Simd<u8, 0>` has zero elements |
Contributor
There was a problem hiding this comment.
Could you also add a testcase for SimdLayoutError::TooManyLanes?
So sth like static VAR2: Simd<u8, 1_000_000>;
Previously, using a zero-length SIMD type in an extern static would cause an internal compiler error. Now it properly emits a diagnostic error instead of panicking.
88734ae to
b970366
Compare
Contributor
|
@bors r+ rollup |
Contributor
rust-timer
added a commit
that referenced
this pull request
Jan 23, 2026
Rollup merge of #151495 - enthropy7:fix-simd-zero-length-extern-static, r=JonathanBrouwer Fix ICE when using zero-length SIMD type in extern static before my fix using a zero-length SIMD type in an extern static would cause an internal compiler error. now it properly shows a diagnostic error instead of panicking. it was because `LayoutError::InvalidSimd` wasn't handled in `check_static_inhabited` and fell through to a generic `delayed_bug`. i added handling for `InvalidSimd` in `check_static_inhabited` (similar to `SizeOverflow`): when a SIMD type has an invalid layout, we call `emit_err` with `Spanned` to emit a normal error instead of an ICE. compiler now emits a clear error `"the SIMD type Simd<u8, 0> has zero elements"` with the correct span on the type, matching expected compiler behavior. fixes #151451
github-actions Bot
pushed a commit
to rust-lang/rustc-dev-guide
that referenced
this pull request
Jan 26, 2026
…uwer Rollup of 3 pull requests Successful merges: - rust-lang/rust#151412 (diagnostics: suggest deriving Default for enums) - rust-lang/rust#151495 (Fix ICE when using zero-length SIMD type in extern static) - rust-lang/rust#151497 (Fix typo: 'recieve' -> 'receive' in lldb-visualizers.md) r? @ghost
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.
before my fix using a zero-length SIMD type in an extern static would cause an internal compiler error. now it properly shows a diagnostic error instead of panicking. it was because
LayoutError::InvalidSimdwasn't handled incheck_static_inhabitedand fell through to a genericdelayed_bug.i added handling for
InvalidSimdincheck_static_inhabited(similar toSizeOverflow): when a SIMD type has an invalid layout, we callemit_errwithSpannedto emit a normal error instead of an ICE. compiler now emits a clear error"the SIMD type Simd<u8, 0> has zero elements"with the correct span on the type, matching expected compiler behavior.fixes #151451