Skip to content

fix: Don't panic on out-of-range integer literals in const positions#22621

Merged
Veykril merged 1 commit into
rust-lang:masterfrom
shulaoda:06-20-fix_don_t_panic_on_out-of-range_integer_literals_in_const_positions
Jun 20, 2026
Merged

fix: Don't panic on out-of-range integer literals in const positions#22621
Veykril merged 1 commit into
rust-lang:masterfrom
shulaoda:06-20-fix_don_t_panic_on_out-of-range_integer_literals_in_const_positions

Conversation

@shulaoda

@shulaoda shulaoda commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Writing an array length that doesn't fit in usize, like [u8; 18446744073709551616], makes rust-analyzer panic and then spam the log with Propagating panic for cycle head ... over and over.

The problem is in intern_const_ref: it interns the literal with ScalarInt::try_from_uint(..).unwrap(), but try_from_* returns None when the value doesn't fit the target type, so the unwrap() blows up inside a salsa query. I changed those three integer branches (and usize_const) to return an error const instead of unwrapping, so an out-of-range literal is just treated as an error rather than crashing.

Also added a regression test. Running analysis-stats on the repro reports panics: 1 before the change and panics: 0 after.

Closes #22620

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 20, 2026

@Veykril Veykril left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Veykril Veykril enabled auto-merge June 20, 2026 11:10
@Veykril Veykril added this pull request to the merge queue Jun 20, 2026
Merged via the queue into rust-lang:master with commit 688ddb7 Jun 20, 2026
32 of 34 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Array length literal larger than usize::MAX panics hir-ty const interning

3 participants