Fix ICE when a suffixed literal's type doesn't match the expected const arg type#152906
Open
lapla-cogito wants to merge 1 commit intorust-lang:mainfrom
Open
Fix ICE when a suffixed literal's type doesn't match the expected const arg type#152906lapla-cogito wants to merge 1 commit intorust-lang:mainfrom
lapla-cogito wants to merge 1 commit intorust-lang:mainfrom
Conversation
Collaborator
|
HIR ty lowering was modified cc @fmease |
Collaborator
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use Why was this reviewer chosen?The reviewer was selected based on:
|
lapla-cogito
commented
Feb 20, 2026
| @@ -0,0 +1,10 @@ | |||
| //@ compile-flags: --emit=link | |||
Contributor
Author
There was a problem hiding this comment.
This was required to perform MIR analysis.
Comment on lines
-1
to
-18
| error: the constant `5` is not of type `u32` | ||
| --> $DIR/type_const-mismatched-types.rs:4:1 | ||
| | | ||
| LL | type const FREE: u32 = 5_usize; | ||
| | ^^^^^^^^^^^^^^^^^^^^ expected `u32`, found `usize` | ||
|
|
||
| error: the constant `5` is not of type `isize` | ||
| --> $DIR/type_const-mismatched-types.rs:8:1 | ||
| | | ||
| LL | type const FREE2: isize = FREE; | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `usize` | ||
|
|
||
| error[E0308]: mismatched types | ||
| --> $DIR/type_const-mismatched-types.rs:16:27 | ||
| | | ||
| LL | type const N: usize = false; | ||
| | ^^^^^ expected `usize`, found `bool` | ||
|
|
Contributor
Author
There was a problem hiding this comment.
This fix, as mentioned above, fixes the ICE while simultaneously reverting the seemingly redundant error output introduced in #152001 (in fact, this ICE was identified as originating from this PR in the original issue).
6e37307 to
fdf6292
Compare
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.
close #152653
try_lower_anon_const_lit()is a fast path that directly converts literal expressions intoty::Const::Valuefor const arg contexts, bypassing typeck. It did not verify that the type produced bylit_to_const()matched the expected type, allowing a mistyped constant (e.g.i32whereusizewas expected) to reach MIR and cause an ICE during const propagation. Therefore added a type-equality check on thelit_to_const()result so that mismatches fall back to the unevaluated-const path, where regular typeck reports the error.