Skip to content

Conversation

@xacrimon
Copy link
Contributor

@xacrimon xacrimon commented Nov 23, 2025

This PR adds lowering code (similar to how track_caller forwarding works) to async fn items and async || closures such that any inline attributes put on them are inherited by the generated coroutine (corresponding to the poll() implementation) and are not applied to the outer function. This behavior matches the accepted FCP in the first linked issue.

Code like the following now correctly codegen 3 functions

  • async_fn_test::consumer
  • async_fn_test::hi::{closure#0}
  • core::ptr::drop_in_place::<async_fn_test::hi::{closure#0}>
#[inline(never)]
pub async fn hi() -> i32 {
    1337
}

pub fn consumer(cx: &mut Context<'_>) -> Option<i32> {
    let fut = hi();
    let pinned = pin!(fut);
    match pinned.poll(cx) {
        Poll::Ready(value) => Some(value),
        Poll::Pending => None,
    }
}

Fixes #129347 and fixes #106765.

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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 Nov 23, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 23, 2025

r? @JonathanBrouwer

rustbot has assigned @JonathanBrouwer.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot

This comment has been minimized.

@xacrimon xacrimon force-pushed the acrimon/async-fn-inline-attr branch from 46d6c3e to d89022a Compare November 23, 2025 20:55
@rust-log-analyzer

This comment has been minimized.

@xacrimon xacrimon force-pushed the acrimon/async-fn-inline-attr branch 4 times, most recently from 2757a30 to 9478bfd Compare November 23, 2025 23:01
@xacrimon xacrimon force-pushed the acrimon/async-fn-inline-attr branch from 9478bfd to fa35f7b Compare November 23, 2025 23:25
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-20-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

296    |
297    = help: `#[rustc_force_inline]` can only be applied to functions
298 
- error: attribute cannot be applied to a `async`, `gen` or `async gen` function
-   --> $DIR/invalid.rs:135:1
-    |
- LL | #[rustc_force_inline]
-    | ^^^^^^^^^^^^^^^^^^^^^
- LL |
- LL | async fn async_foo() {}
-    | -------------------- `async`, `gen` or `async gen` function
- 
- error: attribute cannot be applied to a `async`, `gen` or `async gen` function
-   --> $DIR/invalid.rs:139:1
-    |
- LL | #[rustc_force_inline]
-    | ^^^^^^^^^^^^^^^^^^^^^
- LL |
- LL | gen fn gen_foo() {}
-    | ---------------- `async`, `gen` or `async gen` function
- 
- error: attribute cannot be applied to a `async`, `gen` or `async gen` function
-   --> $DIR/invalid.rs:143:1
-    |
- LL | #[rustc_force_inline]
-    | ^^^^^^^^^^^^^^^^^^^^^
- LL |
- LL | async gen fn async_gen_foo() {}
-    | ---------------------------- `async`, `gen` or `async gen` function
- 
- error: aborting due to 36 previous errors
+ error: aborting due to 33 previous errors
327 
328 Some errors have detailed explanations: E0539, E0805.
---
To only update this specific test, also pass `--test-args force-inlining/invalid.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/force-inlining/invalid.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/force-inlining/invalid" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "--edition=2024"
stdout: none
--- stderr -------------------------------
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
##[error]  --> /checkout/tests/ui/force-inlining/invalid.rs:131:11
   |
LL | fn barqux(#[rustc_force_inline] _x: u32) {}
   |           ^^^^^^^^^^^^^^^^^^^^^

error[E0805]: malformed `rustc_force_inline` attribute input
##[error]  --> /checkout/tests/ui/force-inlining/invalid.rs:15:1
   |
LL | #[rustc_force_inline(bar, baz)]
   | ^^^^^^^^^^^^^^^^^^^^----------^
   |                     |
   |                     expected a single argument here
   |
help: try changing it to one of the following valid forms of the attribute
   |
LL - #[rustc_force_inline(bar, baz)]
LL + #[rustc_force_inline = "reason"]
   |
LL - #[rustc_force_inline(bar, baz)]
LL + #[rustc_force_inline(reason)]
   |
LL - #[rustc_force_inline(bar, baz)]
LL + #[rustc_force_inline]
   |

error[E0539]: malformed `rustc_force_inline` attribute input
##[error]  --> /checkout/tests/ui/force-inlining/invalid.rs:20:1
   |
---
   |
LL - #[rustc_force_inline(2)]
LL + #[rustc_force_inline = "reason"]
   |
LL - #[rustc_force_inline(2)]
LL + #[rustc_force_inline(reason)]
   |
LL - #[rustc_force_inline(2)]
LL + #[rustc_force_inline]
   |

---
   |
LL - #[rustc_force_inline = 2]
LL + #[rustc_force_inline = "reason"]
   |
LL - #[rustc_force_inline = 2]
LL + #[rustc_force_inline(reason)]
   |
LL - #[rustc_force_inline = 2]
LL + #[rustc_force_inline]
   |

---

error: `#[rustc_force_inline]` attribute cannot be used on function params
##[error]  --> /checkout/tests/ui/force-inlining/invalid.rs:72:10
   |
LL | enum Bar<#[rustc_force_inline] T> {
   |          ^^^^^^^^^^^^^^^^^^^^^
   |
   = help: `#[rustc_force_inline]` can only be applied to functions

error: `#[rustc_force_inline]` attribute cannot be used on enum variants
---

error: `#[rustc_force_inline]` attribute cannot be used on function params
##[error]  --> /checkout/tests/ui/force-inlining/invalid.rs:131:11
   |
LL | fn barqux(#[rustc_force_inline] _x: u32) {}
   |           ^^^^^^^^^^^^^^^^^^^^^
   |
   = help: `#[rustc_force_inline]` can only be applied to functions

error: `#[rustc_force_inline]` attribute cannot be used on closures
##[error]  --> /checkout/tests/ui/force-inlining/invalid.rs:148:14
   |
LL |     let _x = #[rustc_force_inline] || { };
   |              ^^^^^^^^^^^^^^^^^^^^^
   |
   = help: `#[rustc_force_inline]` can be applied to functions and inherent methods

error: `#[rustc_force_inline]` attribute cannot be used on expressions
##[error]  --> /checkout/tests/ui/force-inlining/invalid.rs:150:14
   |
LL |     let _y = #[rustc_force_inline] 3 + 4;
   |              ^^^^^^^^^^^^^^^^^^^^^
   |
   = help: `#[rustc_force_inline]` can only be applied to functions

error: `#[rustc_force_inline]` attribute cannot be used on statements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) 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.

#[inline(never)] does not work for async functions #[inline(never)] does not work for async fn

4 participants