Fix ICE when a suffixed literal's type doesn't match the expected const arg type#152906
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
Conversation
|
HIR ty lowering was modified cc @fmease |
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| @@ -0,0 +1,10 @@ | |||
| //@ compile-flags: --emit=link | |||
There was a problem hiding this comment.
This was required to perform MIR analysis.
There was a problem hiding this comment.
Do you mean forcing codegen? If so check out the build-fail directive.
There was a problem hiding this comment.
Do you mean forcing codegen?
No, this ICE occurs when rustc reaches the MIR analysis stage despite the presence of type errors. I think the build-fail directive is inappropriate here because, IIUC, it first requires the check pass to succeed. However, this test contains type errors that cause the check pass to fail, so compiletest aborts the test before ever reaching the full build where the ICE would occur.
| 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` | ||
|
|
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
|
r? BoxyUwU |
|
|
fdf6292 to
b4cf9dd
Compare
|
This change also fixes the newly reported issue #152962, so I’ve added a test for it. |
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
b4cf9dd to
7dfc407
Compare
|
@rustbot ready |
|
this looks good to me though im unsure how this overlaps with #153075 as that will change what I would expect that there's a more fundamental problem here that some part of the compiler isnt expecting for a type const to normalize to something of an incorrect type. I don't think the right way to fix that is in HIR ty lowering instead we probably need to be doing error tainting better somewhere but I don't fully understand what's actually going wrong and where 🤔 We certainly want |
|
Looking at #153075, I understand that literals will be handled as
I'd also be happy to merge the current fix as-is (with an updated commit message and with the tests added in this PR removed, since it would no longer prevent the ICE once #153075 lands) and address the deeper issue in a follow-up PR. |
|
☔ The latest upstream changes (presumably #153116) made this pull request unmergeable. Please resolve the merge conflicts. |
close #152653
close #152962
const_lit_matches_ty()ignored literal suffixes - e.g.LitKind::Int(..)discarded theLitIntTypeandty::Uint(_)matched any unsigned type, so0u8was accepted forusize. This let thetry_lower_anon_const_lit()fast path produce a mistypedty::Const::Value, causing an ICE in MIR const propagation.