Skip to content

avoid accessing uninferred closure upvars in diagnostics - #162595

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
amirHdev:uninferred-upvars
Sep 24, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
amirHdev:uninferred-upvars

Conversation

@amirHdev

@amirHdev amirHdev commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

fixes #162440

note_closure_capture can run before closure capture analysis has finished and the upvar tuple may still be an inference variable at that point and calling upvar_tys() causes an ICE

we can just fall back to the existing closure-level note and wait until the upvar types are available before trying to emit the more specific capture note

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Sep 10, 2026
@amirHdev
amirHdev marked this pull request as ready for review September 10, 2026 14:29
@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 Sep 10, 2026

let captures: Vec<_> =
typeck_results.closure_min_captures_flattened(closure_def_id).collect();
let upvar_tys = upvar_args.upvar_tys();

@lcnr lcnr Sep 21, 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.

instead of fetching them twice, only use tupled_upvars_ty and match on it?

View changes since the review

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.

you haven't actually done that change, have you?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks
fixed this now

@amirHdev
amirHdev force-pushed the uninferred-upvars branch 2 times, most recently from 8670aa1 to 005ce6d Compare September 21, 2026 12:48
@rust-log-analyzer

This comment has been minimized.

@amirHdev
amirHdev force-pushed the uninferred-upvars branch 2 times, most recently from 8ef966d to f535520 Compare September 21, 2026 13:35
Comment on lines +3796 to +3797
ty::Infer(_) => return false,
_ => return false,

@lcnr lcnr Sep 21, 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.

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.

the ? was about why you had both a ty::Infer(_) => return false and a catch all _ => return false branch. Either only have the catch all, or the correct thing here,

return false for ty::Infer and make the catch all unreachable!

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.

I am confused at what is going on here 🤔 does my last comment make sense to you and did you implement the change I mentioned here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry
I saw your comment but somehow missed the actual change you were asking for 😅

@amirHdev
amirHdev force-pushed the uninferred-upvars branch 2 times, most recently from 6bdbafb to d5972e6 Compare September 21, 2026 15:26
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
@amirHdev
amirHdev force-pushed the uninferred-upvars branch 3 times, most recently from f2bb7cc to c263e3d Compare September 24, 2026 09:43
@amirHdev
amirHdev requested a review from lcnr September 24, 2026 09:48
@lcnr

lcnr commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

📌 Commit c263e3d 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 Sep 24, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 24, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #163218 (stdarch subtree update)
 - #159287 (Build a new incr comp session dir from scratch every time)
 - #163222 (Enable EII tests for cg_gcc)
 - #163251 (cg_gcc subtree sync 2026-09-24)
 - #162595 (avoid accessing uninferred closure upvars in diagnostics)
 - #162937 (do generic_const_args Const::Ty hack only on projection consts)
 - #163238 (Fix incorrect use of await in parser suggestion)
@rust-bors
rust-bors Bot merged commit be3bb9f into rust-lang:main Sep 24, 2026
26 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 24, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 24, 2026
Rollup merge of #162595 - amirHdev:uninferred-upvars, r=lcnr

avoid accessing uninferred closure upvars in diagnostics

fixes #162440

`note_closure_capture` can run before closure capture analysis has finished and the upvar tuple may still be an inference variable at that point and calling `upvar_tys()` causes an ICE

we can just fall back to the existing closure-level note and wait until the upvar types are available before trying to emit the more specific capture note
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Sep 25, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#163218 (stdarch subtree update)
 - rust-lang/rust#159287 (Build a new incr comp session dir from scratch every time)
 - rust-lang/rust#163222 (Enable EII tests for cg_gcc)
 - rust-lang/rust#163251 (cg_gcc subtree sync 2026-09-24)
 - rust-lang/rust#162595 (avoid accessing uninferred closure upvars in diagnostics)
 - rust-lang/rust#162937 (do generic_const_args Const::Ty hack only on projection consts)
 - rust-lang/rust#163238 (Fix incorrect use of await in parser suggestion)
bjorn3 pushed a commit to rust-lang/rustc_codegen_cranelift that referenced this pull request Sep 28, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#163218 (stdarch subtree update)
 - rust-lang/rust#159287 (Build a new incr comp session dir from scratch every time)
 - rust-lang/rust#163222 (Enable EII tests for cg_gcc)
 - rust-lang/rust#163251 (cg_gcc subtree sync 2026-09-24)
 - rust-lang/rust#162595 (avoid accessing uninferred closure upvars in diagnostics)
 - rust-lang/rust#162937 (do generic_const_args Const::Ty hack only on projection consts)
 - rust-lang/rust#163238 (Fix incorrect use of await in parser suggestion)
clarfonthey pushed a commit to clarfonthey/stdarch that referenced this pull request Sep 30, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#163218 (stdarch subtree update)
 - rust-lang/rust#159287 (Build a new incr comp session dir from scratch every time)
 - rust-lang/rust#163222 (Enable EII tests for cg_gcc)
 - rust-lang/rust#163251 (cg_gcc subtree sync 2026-09-24)
 - rust-lang/rust#162595 (avoid accessing uninferred closure upvars in diagnostics)
 - rust-lang/rust#162937 (do generic_const_args Const::Ty hack only on projection consts)
 - rust-lang/rust#163238 (Fix incorrect use of await in parser suggestion)
github-actions Bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Oct 2, 2026
…nathanBrouwer

Rollup of 7 pull requests

Successful merges:

 - rust-lang#163218 (stdarch subtree update)
 - rust-lang#159287 (Build a new incr comp session dir from scratch every time)
 - rust-lang#163222 (Enable EII tests for cg_gcc)
 - rust-lang#163251 (cg_gcc subtree sync 2026-09-24)
 - rust-lang#162595 (avoid accessing uninferred closure upvars in diagnostics)
 - rust-lang#162937 (do generic_const_args Const::Ty hack only on projection consts)
 - rust-lang#163238 (Fix incorrect use of await in parser suggestion)
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. 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 upvar_tys called before capture types are inferred

4 participants