Skip to content

Support move expressions in coroutine closures#157738

Open
TaKO8Ki wants to merge 7 commits into
rust-lang:mainfrom
TaKO8Ki:move-expr-coroutine-closures
Open

Support move expressions in coroutine closures#157738
TaKO8Ki wants to merge 7 commits into
rust-lang:mainfrom
TaKO8Ki:move-expr-coroutine-closures

Conversation

@TaKO8Ki

@TaKO8Ki TaKO8Ki commented Jun 11, 2026

Copy link
Copy Markdown
Member

This adds move(expr) support for coroutine closures.

  • Support for move expressions in coroutine closures
  • Support for move expressions in async blocks

RFC: rust-lang/rfcs#3968
Tracking issue: #155050
Project goal:

r? @nikomatsakis

@rustbot

rustbot commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@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 Jun 11, 2026
@rustbot

rustbot commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

nikomatsakis is currently at their maximum review capacity.
They may take a while to respond.

@TaKO8Ki TaKO8Ki force-pushed the move-expr-coroutine-closures branch from b119411 to 219db1c Compare June 22, 2026 17:35
@rustbot

This comment has been minimized.

@TaKO8Ki TaKO8Ki force-pushed the move-expr-coroutine-closures branch from 219db1c to 0f62aac Compare July 16, 2026 11:38
@rustbot

rustbot commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

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.

@nikomatsakis nikomatsakis left a comment

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.

Hmm. Something seems off here. I think we need more tests around nested-move and async blocks, async closures, and gen blocks. For example I'd expect:

let c: Arc<String> = Default::default();
let future = async {
    let f = async {
        move(c.clone());
    };
    assert!( /* c ref count is 2 */ );
    f.await;
    assert!( /* c ref count is 1 */ );
    drop(c);
};
let c: Arc<String> = Default::default();
let future = async {
    let f = async {
        move(c.clone());
    };
    f.await;
    drop(c);
};
println!("{c}"); // <-- ERROR: c is moved
let c: Arc<String> = Default::default();
let future = async {
    let f = async {
        move(move(c.clone()));
    };
    assert!( /* c ref count is 3 */ );
    f.await;
    assert!( /* c ref count is 2 */ );
    drop(c);
};
println!("{c}"); // OK, prints ""

View changes since this review


let y = Arc::new(String::from("nested"));
assert_eq!(Arc::strong_count(&y), 1);
let fut = async { move(move(y.clone())) };

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.

Huh, this is somewhat surprising to me. I expected an error for this example.

Is this an artifact of the desugaring?

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.

3 participants