Skip to content

Fix ICE in transmutability error reporting when type aliases are normalized#151703

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
zedddie:fix-151462-ice
Feb 19, 2026
Merged

Fix ICE in transmutability error reporting when type aliases are normalized#151703
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
zedddie:fix-151462-ice

Conversation

@zedddie
Copy link
Contributor

@zedddie zedddie commented Jan 26, 2026

Fixes #151462

Transmutability error reporting hit an ICE when type aliases were normalized for diagnostics. For example, when type
JustUnit = () normalizes to (), the check passes unexpectedly even though the original check with JustUnit failed.

Fixed by adding a retry in the Answer::Yes arm that checks with the root obligation's types before panicking. The retry only occurs when the root obligation differs and is a Transmute trait predicate.

Also added a test that reproduces the original ICE.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 26, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 26, 2026

r? @jdonszelmann

rustbot has assigned @jdonszelmann.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Comment on lines 2922 to 2925
if obligation.predicate != root_obligation.predicate {
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(root_pred)) =
root_obligation.predicate.kind().skip_binder()
&& root_pred.def_id() == trait_pred.trait_ref.def_id
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if obligation.predicate != root_obligation.predicate {
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(root_pred)) =
root_obligation.predicate.kind().skip_binder()
&& root_pred.def_id() == trait_pred.trait_ref.def_id
if obligation.predicate != root_obligation.predicate
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(root_pred)) =
root_obligation.predicate.kind().skip_binder()
&& root_pred.def_id() == trait_pred.trait_ref.def_id

@Kivooeo
Copy link
Member

Kivooeo commented Jan 26, 2026

Btw, I'm curious, there is a comment

// Should never get a Yes at this point! We already ran it before, and did not get a Yes.

If I understand this correctly, we should never reach this branch, but for some point we do, this brings me to believe that the problem occurs somewhere earlier

@zedddie
Copy link
Contributor Author

zedddie commented Jan 26, 2026

Yes, I've thought about this too, and I tried to use root obligation check earlier to leave the Answer::Yes arm untouched, but it seems to regress diagnostics like bool-mut test(/tests/ui/transmutability/primitives/bool-mut.stderr) from

error[E0277]: `u8` cannot be safely transmuted into `bool`
   ^^^^^^^^^^^^^^^ at least one value of `u8` isn't a bit-valid value of `bool`

to

error[E0277]: `&mut bool` cannot be safely transmuted into `&mut u8`
   ^^^^^^^^^^^^^^^ unsatisfied trait bound
   = help: the nightly-only, unstable trait `TransmuteFrom<u8, ...>` is not implemented for `bool`

which looks incorrect to me. I've thought about this and recheck with root obligation to ensure we are dealing with same type in the Answer::Yes seems reasonable. If it is an incorrect approach I'd like to reimplement this check earlier in error reporting logic, leaving Answer::Yes untouched.

@zedddie
Copy link
Contributor Author

zedddie commented Jan 26, 2026

Actually, It seems to be there is a better place for this check which will not cause diagnostics regression, I will deal with that tommorow

@zedddie
Copy link
Contributor Author

zedddie commented Jan 27, 2026

I am a bit stuck in finding the right place for a check, as it will recheck after transmutability inconsistency, which is basically the same Answer::Yes handling logic but in other place, so I will wait for reviewer to clarify and decide next moves.

@Kivooeo
Copy link
Member

Kivooeo commented Jan 27, 2026

that's totally fine! thanks for getting back and explain your reasoning, that's very valuable

but i'm afraid that i would not be able to dive into this because of being busy this week

@jdonszelmann
Copy link
Contributor

@zedddie where is the place you're referring to? could you factor it out into a function?

@zedddie
Copy link
Contributor Author

zedddie commented Jan 28, 2026

In the report_selection_error function before we call get_safe_transmute_error_and_reason. I thought about adding a second check with root obligations after we get inconsistency when trying to get transmute error and reason.

About factoring out to a function, what comes to mind is creating a function which will check is_transmutable and then if got inconsistency, recheck with root obligations, and if not, will proceed with the normalized.

Am I on the right track?

@jdonszelmann
Copy link
Contributor

Yea, that seems reasonable, and then because it follows largely the same code path we can be reasonably sure the same cases do and don't error

@rustbot
Copy link
Collaborator

rustbot commented Jan 29, 2026

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.

@zedddie
Copy link
Contributor Author

zedddie commented Jan 29, 2026

after some time away from computer I think my function is a bit unreadable, I will refactor it a bit

@zedddie
Copy link
Contributor Author

zedddie commented Feb 13, 2026

@jdonszelmann hi, can you take a look please? does it look good or I should change something?

@jdonszelmann
Copy link
Contributor

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 18, 2026

📌 Commit a257fb9 has been approved by jdonszelmann

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 18, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 18, 2026
…mann

Fix ICE in transmutability error reporting when type aliases are normalized

Fixes rust-lang#151462

Transmutability error reporting hit an ICE when type aliases were normalized for diagnostics. For example, when type
 `JustUnit = ()` normalizes to `()`, the check passes unexpectedly even though the original check with `JustUnit` failed.

Fixed by adding a retry in the `Answer::Yes` arm that checks with the root obligation's types before panicking. The retry only occurs when the root obligation differs and is a Transmute trait predicate.

Also added a test that reproduces the original ICE.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 18, 2026
…mann

Fix ICE in transmutability error reporting when type aliases are normalized

Fixes rust-lang#151462

Transmutability error reporting hit an ICE when type aliases were normalized for diagnostics. For example, when type
 `JustUnit = ()` normalizes to `()`, the check passes unexpectedly even though the original check with `JustUnit` failed.

Fixed by adding a retry in the `Answer::Yes` arm that checks with the root obligation's types before panicking. The retry only occurs when the root obligation differs and is a Transmute trait predicate.

Also added a test that reproduces the original ICE.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 18, 2026
…mann

Fix ICE in transmutability error reporting when type aliases are normalized

Fixes rust-lang#151462

Transmutability error reporting hit an ICE when type aliases were normalized for diagnostics. For example, when type
 `JustUnit = ()` normalizes to `()`, the check passes unexpectedly even though the original check with `JustUnit` failed.

Fixed by adding a retry in the `Answer::Yes` arm that checks with the root obligation's types before panicking. The retry only occurs when the root obligation differs and is a Transmute trait predicate.

Also added a test that reproduces the original ICE.
rust-bors bot pushed a commit that referenced this pull request Feb 18, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #152799 (Subtree sync for rustc_codegen_cranelift)
 - #152569 (Stop using rustc_layout_scalar_valid_range_* in rustc)
 - #151059 (x86: support passing `u128`/`i128` to inline assembly)
 - #152097 (Suggest local variables for captured format args)
 - #152734 (Respect the `--ci` flag in more places in bootstrap)
 - #151703 (Fix ICE in transmutability error reporting when type aliases are normalized)
 - #152173 (Reflection TypeKind::FnPtr)
 - #152564 (Remove unnecessary closure.)
 - #152628 (tests: rustc_public: Check const allocation for all variables (1 of 11 was missing))
 - #152658 (compiletest: normalize stderr before SVG rendering)
 - #152766 (std::r#try! - avoid link to nightly docs)
 - #152780 (Remove some clones in deriving)
 - #152787 (Add a mir-opt test for alignment check generation [zero changes outside tests])
 - #152790 (Fix incorrect target in aarch64-unknown-linux-gnu docs)
 - #152792 (Fix an ICE while checking param env shadowing on an erroneous trait impl)
 - #152793 (Do no add -no-pie on Windows)
 - #152803 (Avoid delayed-bug ICE for malformed diagnostic attrs)
 - #152806 (interpret: fix comment typo)
rust-bors bot pushed a commit that referenced this pull request Feb 19, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #152799 (Subtree sync for rustc_codegen_cranelift)
 - #152814 (stdarch subtree update)
 - #151059 (x86: support passing `u128`/`i128` to inline assembly)
 - #152097 (Suggest local variables for captured format args)
 - #152734 (Respect the `--ci` flag in more places in bootstrap)
 - #151703 (Fix ICE in transmutability error reporting when type aliases are normalized)
 - #152173 (Reflection TypeKind::FnPtr)
 - #152564 (Remove unnecessary closure.)
 - #152628 (tests: rustc_public: Check const allocation for all variables (1 of 11 was missing))
 - #152658 (compiletest: normalize stderr before SVG rendering)
 - #152766 (std::r#try! - avoid link to nightly docs)
 - #152780 (Remove some clones in deriving)
 - #152787 (Add a mir-opt test for alignment check generation [zero changes outside tests])
 - #152790 (Fix incorrect target in aarch64-unknown-linux-gnu docs)
 - #152792 (Fix an ICE while checking param env shadowing on an erroneous trait impl)
 - #152793 (Do no add -no-pie on Windows)
 - #152803 (Avoid delayed-bug ICE for malformed diagnostic attrs)
 - #152806 (interpret: fix comment typo)
rust-bors bot pushed a commit that referenced this pull request Feb 19, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #152799 (Subtree sync for rustc_codegen_cranelift)
 - #152814 (stdarch subtree update)
 - #151059 (x86: support passing `u128`/`i128` to inline assembly)
 - #152097 (Suggest local variables for captured format args)
 - #152734 (Respect the `--ci` flag in more places in bootstrap)
 - #151703 (Fix ICE in transmutability error reporting when type aliases are normalized)
 - #152173 (Reflection TypeKind::FnPtr)
 - #152564 (Remove unnecessary closure.)
 - #152628 (tests: rustc_public: Check const allocation for all variables (1 of 11 was missing))
 - #152658 (compiletest: normalize stderr before SVG rendering)
 - #152766 (std::r#try! - avoid link to nightly docs)
 - #152780 (Remove some clones in deriving)
 - #152787 (Add a mir-opt test for alignment check generation [zero changes outside tests])
 - #152790 (Fix incorrect target in aarch64-unknown-linux-gnu docs)
 - #152792 (Fix an ICE while checking param env shadowing on an erroneous trait impl)
 - #152793 (Do no add -no-pie on Windows)
 - #152803 (Avoid delayed-bug ICE for malformed diagnostic attrs)
 - #152806 (interpret: fix comment typo)
@rust-bors rust-bors bot merged commit d7ad9f7 into rust-lang:main Feb 19, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Feb 19, 2026
rust-timer added a commit that referenced this pull request Feb 19, 2026
Rollup merge of #151703 - zedddie:fix-151462-ice, r=jdonszelmann

Fix ICE in transmutability error reporting when type aliases are normalized

Fixes #151462

Transmutability error reporting hit an ICE when type aliases were normalized for diagnostics. For example, when type
 `JustUnit = ()` normalizes to `()`, the check passes unexpectedly even though the original check with `JustUnit` failed.

Fixed by adding a retry in the `Answer::Yes` arm that checks with the root obligation's types before panicking. The retry only occurs when the root obligation differs and is a Transmute trait predicate.

Also added a test that reproduces the original ICE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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]: Inconsistent rustc_transmute::is_transmutable(...) result, got Yes

4 participants

Comments