Open
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())
}