Skip to content

Resolved issue with mismatched types triggering ICE in certain scenarios #141236

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

Merged
merged 1 commit into from
May 20, 2025

Conversation

jagunter
Copy link
Contributor

@jagunter jagunter commented May 18, 2025

Background

The function annotate_mut_binding_to_immutable_binding called in emit_coerce_suggestions performs a type comparison between the expected and found types from ExpectedFound in the TypeError. This can fail if the found type contains a region variable that's been rolled back.

What is being changed?

This updates annotate_mut_binding_to_immutable_binding to use expr_ty and expected from the parent function instead of the types from the TypeError. This sidesteps the issue of using found from TypeError which may leak lingering inference region variables.

This does change the diagnostic behavior to only support cases where the expected outermost type is &T, but that seems to be the intended functionality.

Also fixed the example in the annotate_mut_binding_to_immutable_binding rustdocs.

r? rust-lang/types

Fixes #140823

@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 May 18, 2025
@rust-log-analyzer

This comment has been minimized.

@jagunter
Copy link
Contributor Author

Aside, #141225 (currently open) includes an ICE test for this issue. Will need to coordinate depending on which lands first

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

It's kind of a shame that this hack needs to exist; the root cause is that we're leaking infer vars out of probes.

Is it possible instead to pass down the root type (i.e. the type of expr itself) and the corresponding expected type, rather than looking into the TypeError? This would mean we only detect this when the outermost type is &T, but I don't think this diagnostic even knows how to apply to other cases?

Please also squash the commit history into one commit, since this is a pretty small change and doesn't need a complicated history.

@compiler-errors
Copy link
Member

Aside, #141225 (currently open) includes an ICE test for this issue.

Yeah, just rebase it and delete the test when it makes it onto master. Since this PR needs some tweaking, I think that PR will land first anyways.

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented May 19, 2025

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

@jagunter jagunter requested a review from compiler-errors May 20, 2025 01:35
@compiler-errors
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented May 20, 2025

📌 Commit db1ac98 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors 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 May 20, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request May 20, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#139419 (Error on recursive opaque ty in HIR typeck)
 - rust-lang#141236 (Resolved issue with mismatched types triggering ICE in certain scenarios)
 - rust-lang#141253 (Warning added when dependency crate has async drop types, and the feature is disabled)
 - rust-lang#141269 (rustc-dev-guide subtree update)
 - rust-lang#141275 (`gather_locals`: only visit guard pattern guards when checking the guard)
 - rust-lang#141279 (`lower_to_hir` cleanups)
 - rust-lang#141285 (Add tick to `RePlaceholder` debug output)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 42ed69c into rust-lang:master May 20, 2025
6 checks passed
@rustbot rustbot added this to the 1.89.0 milestone May 20, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 20, 2025
Rollup merge of rust-lang#141236 - jagunter:issue-140823, r=compiler-errors

Resolved issue with mismatched types triggering ICE in certain scenarios

## Background

The function `annotate_mut_binding_to_immutable_binding` called in `emit_coerce_suggestions` performs a type comparison between the `expected` and `found` types from `ExpectedFound` in the `TypeError`. This can fail if the `found` type contains a region variable that's been rolled back.

## What is being changed?

This updates `annotate_mut_binding_to_immutable_binding` to use `expr_ty` and `expected` from the parent function instead of the types from the `TypeError`. This sidesteps the issue of using `found` from `TypeError` which may leak lingering inference region variables.

This does change the diagnostic behavior to _only_ support cases where the expected outermost type is `&T`, but that seems to be the intended functionality.

Also fixed the example in the `annotate_mut_binding_to_immutable_binding` rustdocs.

r? rust-lang/types

Fixes rust-lang#140823
@jagunter jagunter deleted the issue-140823 branch May 20, 2025 20:16
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.

Attempting to store function callback of a particular incorrect type produces ICE
6 participants