-
Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-asyncWorking group: Async & awaitWorking group: Async & await
Description
I tried this code:
#[inline(never)]
async foo() {
// ...
}https://rust.godbolt.org/z/97P1Goqhx
I expected to see this happen: logic code in async functions will not be inlined.
Instead, this happened: Only the function itself is not inlined, and the Future it returns is fully inlined.
I believe this is because async fn is desugared to
#[inline(never)]
fn foo() -> impl Future<Output = ()> {
async move {
// ...
}
}To get desired effect, I need to write
struct NoInline<F>(F);
impl<F: Future> Future for NoInline<F> {
type Output = F::Output;
#[inline(never)]
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
// ...
}
}
#[inline]
fn foo() -> impl Future<Output = ()> {
async fn foo_inner() {
// ...
}
NoInline(foo_inner())
}Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-asyncWorking group: Async & awaitWorking group: Async & await