Skip to content

Avoid inserting invalid Subtype casts when types don't relate#156463

Closed
reddevilmidzy wants to merge 1 commit into
rust-lang:mainfrom
reddevilmidzy:mgca-mir
Closed

Avoid inserting invalid Subtype casts when types don't relate#156463
reddevilmidzy wants to merge 1 commit into
rust-lang:mainfrom
reddevilmidzy:mgca-mir

Conversation

@reddevilmidzy

Copy link
Copy Markdown
Member

close: #154748
close: #154750

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 11, 2026
@reddevilmidzy

Copy link
Copy Markdown
Member Author

I first tried fixing this during literal-to-const lowering, but that either changed the existing diagnostics or introduced additional delayed-bug ICEs.

The type mismatch is already diagnosed earlier, so this instead makes known_panics_lint bail out on incompatible layouts during const propagation to avoid the ICE while preserving the current errors.

@reddevilmidzy reddevilmidzy changed the title Avoid ICE in known_panics_lint for mismatched type const literals Avoid ICE in known_panics_lint for mismatched type const literals May 11, 2026
@reddevilmidzy

Copy link
Copy Markdown
Member Author

r? @BoxyUwU

@rustbot

rustbot commented May 12, 2026

Copy link
Copy Markdown
Collaborator

BoxyUwU is currently at their maximum review capacity.
They may take a while to respond.

@reddevilmidzy reddevilmidzy marked this pull request as ready for review May 12, 2026 02:38
@rustbot

rustbot commented May 12, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 12, 2026
_ => return None,
}

if value.layout.size != to.size {

@oli-obk oli-obk May 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This fixes the symptom, not the issue itself. Why do we even get here after the error is reported?

Oh I think I may have found it: https://github.com/rust-lang/rust/pull/152001/changes#r3224335944

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for taking a look!

For this testcase, lower_const_arg_literal does not hit the None branch. lit_to_const returns Some(value), so the literal keeps its own type, and the mismatch is only rejected later by the ConstArgHasType obligation.

add_subtyping_projections then turns the mismatched assignment into a CastKind::Subtype, even though the types are not actually related. So instead of guarding in known_panics_lint, I changed add_subtyping_projections to avoid inserting a Subtype cast for this kind of unrelated mismatch.

@reddevilmidzy reddevilmidzy changed the title Avoid ICE in known_panics_lint for mismatched type const literals Avoid inserting invalid Subtype casts when types don't relate May 22, 2026
@BoxyUwU

BoxyUwU commented Jun 7, 2026

Copy link
Copy Markdown
Member

in theory this overlaps with #154853 there we also are solving the problem of type const normalization changing types of values causing ICEs in later parts of the compiler 🤔

@reddevilmidzy

Copy link
Copy Markdown
Member Author

in theory this overlaps with #154853 there we also are solving the problem of type const normalization changing types of values causing ICEs in later parts of the compiler 🤔

Ah, you're right. I checked out #154853 and confirmed that the ICE no longer occurs there either. I'll close this PR. Thanks!

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 8, 2026
@reddevilmidzy reddevilmidzy deleted the mgca-mir branch June 8, 2026 09:16
@BoxyUwU

BoxyUwU commented Jun 8, 2026

Copy link
Copy Markdown
Member

ah cool, sorry for not realising sooner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: attempting to project to field at offset 0 with size 8 into immediate with layout TyAndLayout [ICE]: invalid field access on immediate

4 participants