Skip to content

Regression in async generator and fmt internals: loss of Send #93274

Closed
@danielhenrymantilla

Description

@danielhenrymantilla

If an .await occurs inside a formatting macro, the resulting generator is no longer Send.

Context

This has already tripped up some people which seem to get quite confused with this error message, so I'd rather we not regress here:

Code

I tried this code:

async fn foo() {
    println!("{} {:?}", "", async {}.await);
}

const _ASSERT_SEND: fn() = || {
    let _: &dyn Send = &foo();
};

I expected to see this happen: Code compiles fine: the type of foo() is Send.

Instead, this happened: The type of foo() is not send, since the backing state-machine generator produced for it now captures part of the fmt internals involving a & reference to the extern { type Opaque; }, which is not Sync.

Version it worked on

It most recently worked on: beta

Version with regression

rustc --version --verbose:

nightly-2022-01-23 84322efad553c7a79c80

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged

Metadata

Metadata

Assignees

Labels

A-async-awaitArea: Async & AwaitC-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions