Make const_lit_matches_ty check literal suffixes for exact type match#152906
Make const_lit_matches_ty check literal suffixes for exact type match#152906lapla-cogito wants to merge 1 commit intorust-lang:mainfrom
const_lit_matches_ty check literal suffixes for exact type match#152906Conversation
|
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. |
This comment has been minimized.
This comment has been minimized.
|
Can you update your tests which used literals by themselves to actually be |
are you using AI? I am boxy you're talking to me |
|
@BoxyUwU That is because I wanted to approach discussion from a more neutral perspective for two reasons: first, because multiple people are participating in this thread (though of course you're currently the primary reviewer :)); and second, because the discussion may be revisited later. For example, if I mention you but writes it that way, it would be unnatural - but that's not the case here. However, I don’t deny that I do use them. Since I’m not a native English speaker, I sometimes use them for translation purposes and to help me better understand codebases. |
7dfc407 to
c8bd109
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
const_lit_matches_ty check literal suffixes for exact type match
This comment has been minimized.
This comment has been minimized.
de1659f to
30c2d6b
Compare
|
@lapla-cogito ah okay I see :) no worries that makes sense |
This comment has been minimized.
This comment has been minimized.
|
Only x86_64-gnu-llvm-20 produces different errors that cause CI to fail, but TBH, I don't really understand the cause... 🤷 edit: While the root cause isn't entirely clear for me, the only plausible suspect is the |
30c2d6b to
80d29cd
Compare
80d29cd to
0bb020a
Compare
const_lit_matches_tyignored literal suffixes. This let thetry_lower_anon_const_litfast path produce a mistypedty::Const::Value, bypassing the type mismatch error that typeck would otherwise report.