Skip to content

check if len of array const arg matches the expected len of the type when lowering to valtree#158587

Open
sjwang05 wants to merge 1 commit into
rust-lang:mainfrom
sjwang05:issue-155168
Open

check if len of array const arg matches the expected len of the type when lowering to valtree#158587
sjwang05 wants to merge 1 commit into
rust-lang:mainfrom
sjwang05:issue-155168

Conversation

@sjwang05

@sjwang05 sjwang05 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

When creating valtrees for arrays passed as const args in lower_const_arg_array, we assume the array has the correct length without actually checking the length of the arg, leading to UB at runtime (#155168) or an ICE during CTFE (#151079). This PR adds a check comparing the expected length of the type with the actual number of elements, similar to lower_const_arg_tup.

fixes #155168

@rustbot

rustbot commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

HIR ty lowering was modified

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 29, 2026
@rustbot

rustbot commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 17 candidates

@sjwang05 sjwang05 changed the title check if len of array const arg matches the expected len check if len of array const arg matches the expected len of the type when lowering to valtree Jun 29, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

constructing invalid value of type [u8; 2]: at [0], encountered uninitialized memory, but expected an integer

4 participants