Skip to content

Conversation

@Delta17920
Copy link

@Delta17920 Delta17920 commented Dec 9, 2025

This fixes an internal compiler error that occurred when normalizing associated types during closure capture analysis.

The Fix: Modified rustc_middle/src/ty/normalize_erasing_regions.rs to gracefully handle projection normalization failures instead of panicking when analyzing closure captures.

Regression Test: Added tests/ui/associated-types/normalization-ice-issue-149746.rs, a reproduction case involving complex associated type projections (<() as Owner>::Ty) that previously crashed the compiler. Verified it now emits a standard type error (E0277).

Fixes #149746

@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 Dec 9, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 9, 2025

r? @fee1-dead

rustbot has assigned @fee1-dead.
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

@rustbot

This comment has been minimized.

@Delta17920
Copy link
Author

Delta17920 commented Dec 9, 2025

r? compiler

@rustbot
Copy link
Collaborator

rustbot commented Dec 9, 2025

fmease is not on the review rotation at the moment.
They may take a while to respond.

@rustbot rustbot assigned compiler-errors and unassigned fee1-dead and fmease Dec 9, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 9, 2025

compiler-errors is not on the review rotation at the moment.
They may take a while to respond.

@rustbot rustbot assigned lcnr and unassigned compiler-errors Dec 9, 2025
@rust-log-analyzer

This comment has been minimized.

let input = self.typing_env.as_query_input(arg);

// 2. Use unwrap_or(arg) to return the original arg if it fails
self.tcx.try_normalize_generic_arg_after_erasing_regions(input).unwrap_or(arg)
Copy link
Contributor

Choose a reason for hiding this comment

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

we're intentionally using a bug! here as we're in normalize_generic_arg_after_erasing_regions.

The issue happens in the caller:

  • we either have to change the caller to use try_normalize... to avoid this ICE if the error is unavoidable
  • or prevent this error entirely by not calling normalize_... for types which aren#t well-formed

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback @lcnr ! I have reverted the global change in rustc_middle and moved the fix to compiler/rustc_hir_typeck/src/upvar.rs as requested. specifically, I updated the needs_drop closure within has_significant_drop_outside_of_captures to use try_normalize_erasing_regions; if normalization fails, it now conservatively returns false (assuming no significant drop) instead of panicking.

@rustbot
Copy link
Collaborator

rustbot commented Dec 9, 2025

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.

@Delta17920
Copy link
Author

@lcnr anything else that needs to be changed?

Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
@Delta17920 Delta17920 requested review from fmease and lcnr December 11, 2025 00:38
@Delta17920
Copy link
Author

Delta17920 commented Dec 11, 2025

@lcnr & @fmease ready to merge ig

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

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE when lint rust_2021_incompatible_closure_captures encounters type that can't be normalized

7 participants