-
Notifications
You must be signed in to change notification settings - Fork 12.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not panic in ty::consts::Const::try_to_target_usize()
in case of size mismatch
#126382
base: master
Are you sure you want to change the base?
Conversation
r? @davidtwco rustbot has assigned @davidtwco. Use |
We intentionally started ICEing here because it is genuinely a bug to be doing this. This PR Is effectively a partial revert of #126159. Ideally what should be happening is we should be tainting errors somewhere so that we can check for |
Looking it into it a little bit the problem is that edit: wrote a bit more in the actual issue itself, should read that too |
r? @BoxyUwU |
--> $DIR/ice-const-size-relate-126359.rs:12:39 | ||
| | ||
LL | let _ = OppOrder::<3, u32> { arr: [0, 0, 0] }; | ||
| ^^^^^^^^^ expected `3`, found `3` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This diagnostic still looks buggy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it should be suppressed. Will look into it
Yeah, as you said for most users of The special situation here is that this is called in an error path. |
Yeah, that's why I felt the solution was simply to prevent the panic. First I thought I should make the change here in rust/compiler/rustc_type_ir/src/relate.rs Lines 502 to 514 in 56e112a
but then it seemed easier to do it inside |
I don't think |
@rustbot author |
= note: expected array `[u32; 3]` | ||
found array `[u32; 3]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wooondering if its worth having a debug_assert
against this kind of stuff ('note: expected X, found Y' where x.display() == y.display()) because that just seems silly from a diagnostic point of view 😅
10bc842
to
f67d045
Compare
I have undone my changes to As for the confusing diagnostics:
and
I'll tackle them later in a separate PR. @rustbot review |
This comment has been minimized.
This comment has been minimized.
… size mismatch Fixes an ICE when we try to relate an array size of type u8 to usize
f67d045
to
a1a0865
Compare
Occurred due to an overdue rebase. Rebased now. |
That seems potentially quite confusing if there are two #126159 was written under the assumption that the compiler can reliably avoid feeding ill-typed programs to later phases. If that is not the case, maybe we should go back to having the |
What if we rename the |
Is it clear where one would want to call which function? Sounds a bit like the one on the inherent impl is just an ICE waiting to happen, it the compiler feeds ill-typed terms so deep into the type system. Is it clear why that happens / why it cannot be prevented? Boxy wrote above "Looking it into it a little bit the problem is that super_relate_tys for TyKind::Array has diagnostic logic in it that unconditionally evaluates the array length to a usize. This codepath should correctly handle length arguments that are incorrectly typed instead of assuming they can be evaluated to a usize." Have you dug to the bottom of why that does not work? |
Fixes #126359
This is the failing code:
The ICE occurred while unifying the type of array
[0, 0, 0]
withOppOrder::<3, u32>.arr
field.arr
's type is malformed because it hasu8
for size instead ofusize
. So when we try to unifyusize
withu8
a method inValtree
panics causing the ICE.This PR makes
ty::consts::Const::try_to_target_usize
, which callsValtree
methods, check for size mismatch and gracefully returnNone
instead of callingValtree
.