Skip to content

async fn drop order for temporaries in return expression does not match sync #64512

Closed
@nikomatsakis

Description

@nikomatsakis

This asynchronous function:

async fn foo_async(x: D, y: D) {
    helper_async(&D()).await
    //                ^^^ temporary D
}

async fn helper_async(v: &D) { }

will drop first y, then x, then the temporary D. However an equivalent synchronous function (playground) would drop the temporary, then y, then x. The problem is our desugaring for async fn, which looks something like this:

// async fn foo_async($parameter_patterns) { $body }
fn foo_async(raw_parameters) {
  async move {
    let $parameter_patterns = raw-parameters;
    $body // body of the async fn
  }
}

here, the temporaries in $body wind up being dropped after the let-bound variables of the block. Proposed fix in a comment below.

Metadata

Metadata

Assignees

Labels

A-async-awaitArea: Async & AwaitAsyncAwait-PolishAsync-await issues that are part of the "polish" areaP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions