Skip to content

Normalize capture place tys to prevent ICE#152165

Merged
rust-bors[bot] merged 9 commits intorust-lang:mainfrom
JohnTitor:issue-151579
Feb 28, 2026
Merged

Normalize capture place tys to prevent ICE#152165
rust-bors[bot] merged 9 commits intorust-lang:mainfrom
JohnTitor:issue-151579

Conversation

@JohnTitor
Copy link
Member

@JohnTitor JohnTitor commented Feb 5, 2026

Fixes #151579
Fixes #120811
r? @lcnr

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Feb 5, 2026
@rust-log-analyzer

This comment has been minimized.

@lcnr lcnr closed this Feb 8, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 8, 2026
@lcnr lcnr reopened this Feb 8, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 8, 2026
HirPlaceBase::Upvar(upvar_id) => {
ty::TypingEnv::post_analysis(tcx, upvar_id.closure_expr_id)
}
_ => ty::TypingEnv::fully_monomorphized(),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is hacky and subtly wrong in two ways.

  • even if the type is not from an upvar, we still need the right param_env to normalize
  • we use this during MIR build, so it should probably use TypingMode::Borrowck or whatever

see https://rustc-dev-guide.rust-lang.org/typing-parameter-envs.html

Copy link
Member Author

@JohnTitor JohnTitor Feb 11, 2026

Choose a reason for hiding this comment

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

Ah I see, I've switched to use try_structurally_resolve_ty as mentioned in the issue: 176bf7d (this PR)
This way, we can avoid deep normalization here, right?

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

ah, I didn't see we always get these types from the typeck_results. We should deeply normalize them in writeback and then assume that they are normalized afterwards

View changes since this review

@rustbot

This comment has been minimized.

@JohnTitor JohnTitor requested a review from lcnr February 11, 2026 11:04
}

fn try_structurally_resolve_place_ty(&self, span: Span, place: &mut Place<'tcx>) {
place.base_ty = self.try_structurally_resolve_type(span, place.base_ty);
Copy link
Contributor

Choose a reason for hiding this comment

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

use deeply_normalize here. We deeply normalize types in the writeback results, so I think we should do the same here

Copy link
Member Author

Choose a reason for hiding this comment

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

Just replacing didn't work so I had to do something like this instead: 750cd53

Is this what you meant for?

Copy link
Contributor

Choose a reason for hiding this comment

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

can you use at.deeply_normalize with both solvers?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've tried but had to construct TraitEngine there which seems an unusual way (I haven't seen such a way in other places).
Instead, I guess using ObligationCtxt might be better here, other places do this way and it shoudl call at.deeply_normalize internally: a7ea420
How about this?

@JohnTitor JohnTitor requested a review from lcnr February 12, 2026 22:32
UpvarMigrationInfo::CapturingPrecise {
source_expr: capture.info.path_expr_id,
var_name: capture.to_string(self.tcx),
var_name: self.place_to_string_for_migration(capture),
Copy link
Contributor

Choose a reason for hiding this comment

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

can we move this normalization even further up so that catpure.place is already deeply normalized and we don't have to do so here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved: c22ffdb
I wonder if we should reduce scope by if next_solver as we now normalize stuff more generally, i.e. other than emitting lint rust_2021_incompatible_closure_captures and it would bring unnecessary cost for most cases 🤔

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

}
}

fn try_structurally_resolve_place_ty(&self, span: Span, place: &mut Place<'tcx>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

deeply_normalize should normalize arbitrary TypeFoldable things. Is Place type foldable?

Also, change this function name :>

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, you're right, it's TypeFoldable. Addressed: 7def3bc
And I noticed we have another win, it would fix #120811 (N.B. crashes/120911 is a dup of 120811, so I removed it).

@rustbot

This comment has been minimized.

@lcnr
Copy link
Contributor

lcnr commented Feb 15, 2026

I messed up by reviewing your commit directly yesterday, see c22ffdb#r177216090

@rustbot

This comment has been minimized.

@JohnTitor
Copy link
Member Author

@lcnr Sorry, I missed it 🙏
I think I addressed your comments: ecdea2c
I need to call normalize_capture_place before capture_information.push to prevent ICEs.

@rustbot
Copy link
Collaborator

rustbot commented Feb 17, 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.

@JohnTitor
Copy link
Member Author

(rebase mistake, sorry for pinging)

let at = self.at(&cause, self.param_env);
match solve::deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals(
at,
place.clone(),
Copy link
Contributor

Choose a reason for hiding this comment

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

why clone?

Copy link
Contributor

Choose a reason for hiding this comment

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

i guess to return some place in the error case?

@lcnr
Copy link
Contributor

lcnr commented Feb 26, 2026

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Feb 26, 2026
Normalize capture place `ty`s to prevent ICE
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 26, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 26, 2026

☀️ Try build successful (CI)
Build commit: 00ebd52 (00ebd52fd0610fe0a77b0caf7ebfb506b3be5e2e, parent: bb779a91568ac1ee0b8a9dcb6b69219ef30b18a3)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (00ebd52): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary 3.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.1% [3.1%, 3.1%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.1% [3.1%, 3.1%] 1

Cycles

Results (secondary -3.9%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.9% [-3.9%, -3.9%] 2
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 480.119s -> 482.867s (0.57%)
Artifact size: 395.65 MiB -> 397.67 MiB (0.51%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 26, 2026
@lcnr
Copy link
Contributor

lcnr commented Feb 27, 2026

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 27, 2026

📌 Commit dddbf96 has been approved by lcnr

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 27, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 28, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 28, 2026
rust-bors bot pushed a commit that referenced this pull request Feb 28, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #153211 (`rust-analyzer` subtree update)
 - #149027 (Improve cross-crate trait impl param mismatch suggestions )
 - #152730 (add field representing types)
 - #153136 (Correctly handle `#[doc(alias = "...")]` attribute on inlined reexports)
 - #152165 (Normalize capture place `ty`s to prevent ICE)
 - #152615 (refactor 'valid for read/write' definition: exclude null)
 - #153109 (Fix LegacyKeyValueFormat report from docker build: aarch64-gnu-debug)
 - #153172 (Fix comment about placeholders)
 - #153187 (Fix ICE when macro-expanded extern crate shadows std)
 - #153190 (Don't allow subdiagnostic to use variables from their parent)
 - #153200 (Remove redundant clone)
 - #153216 (mark two polonius tests as known-bug)
@rust-bors rust-bors bot merged commit 0381e24 into rust-lang:main Feb 28, 2026
12 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Feb 28, 2026
rust-timer added a commit that referenced this pull request Feb 28, 2026
Rollup merge of #152165 - JohnTitor:issue-151579, r=lcnr

Normalize capture place `ty`s to prevent ICE

Fixes #151579
Fixes #120811
r? @lcnr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-rustc-dev-guide Area: rustc-dev-guide A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE with -Znext-solver when accessing hir place ICE: Broken MIR: NoSolution

5 participants