Skip to content

Check coroutine upvars in dtorck constraint#144156

Merged
bors merged 2 commits intorust-lang:masterfrom
compiler-errors:dtorck-upvars
Aug 11, 2025
Merged

Check coroutine upvars in dtorck constraint#144156
bors merged 2 commits intorust-lang:masterfrom
compiler-errors:dtorck-upvars

Conversation

@compiler-errors
Copy link
Copy Markdown
Contributor

@compiler-errors compiler-errors commented Jul 18, 2025

Fix #144155.

This PR fixes an unsoundness where we were not considering coroutine upvars as drop-live if the coroutine interior types (witness types) had nothing which required drop.

In the case that the coroutine does not have any interior types that need to be dropped, then we don't need to treat all of the upvars as use-live; instead, this PR uses the same logic as closures, and descends into the upvar types to collect anything that must be drop-live. The rest of this PR is reworking the comment to explain the behavior here.

r? @lcnr or reassign 😸


Just some thoughts --- a proper fix for this whole situation would be to consider TypingMode in the needs_drop function, and just calling coroutine_ty.needs_drop(tcx, typing_env) in the dtorck constraint check.

During MIR building, we should probably use a typing mode that stalls the local coroutines and considers them to be unconditionally drop, or perhaps just stall all coroutines in analysis mode. Then in borrowck mode, we can re-check needs_drop but descend into witness types properly. #144158 implements this experimentally.

This is a pretty involved fix, and conflicts with some in-flight changes (#144157) that I have around removing coroutine witnesses altogether. I'm happy to add a FIXME to rework this whole approach, but I don't want to block this quick fix since it's obviously more correct than the status-quo.

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

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-types Relevant to the types team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Coroutine upvars are not required to be live in borrowck if witness has no drop requirements

9 participants