Skip to content

Make inline attributes apply to the generated poll in async fn - #149245

Open
xacrimon wants to merge 1 commit into
rust-lang:mainfrom
xacrimon:acrimon/async-fn-inline-attr
Open

Make inline attributes apply to the generated poll in async fn#149245
xacrimon wants to merge 1 commit into
rust-lang:mainfrom
xacrimon:acrimon/async-fn-inline-attr

Conversation

@xacrimon

@xacrimonxacrimon commented Nov 23, 2025

Copy link
Copy Markdown
Contributor

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)]pubasyncfnhi() -> i32{1337}pubfnconsumer(cx:&mutContext<'_>) -> 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.

This has already been FCP'ed here: #129347

@rustbotrustbot 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
Copy Markdown
Collaborator

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
xacrimonforce-pushed the acrimon/async-fn-inline-attr branch from 46d6c3e to d89022aCompareNovember 23, 2025 20:55
@rust-log-analyzer

This comment has been minimized.

@xacrimon
xacrimonforce-pushed the acrimon/async-fn-inline-attr branch 5 times, most recently from 9478bfd to fa35f7bCompareNovember 23, 2025 23:25
@rust-log-analyzer

This comment has been minimized.

@JonathanBrouwer

Copy link
Copy Markdown
Member

@rustbot author
CI is failing

@rustbotrustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 25, 2025
@rustbot

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@bors

bors commented Dec 11, 2025

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #149853) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-bors

rust-borsBot commented Jan 2, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes made this pull request unmergeable. Please resolve the merge conflicts.

@Mark-SimulacrumMark-Simulacrum added the relnotes Marks issues that should be documented in the release notes of the next release. label Jan 25, 2026
@Enselic

Copy link
Copy Markdown
Member

Triage: Are you still working on this @xacrimon?

@xacrimon
xacrimonforce-pushed the acrimon/async-fn-inline-attr branch from fa35f7b to 7054408CompareApril 5, 2026 16:59
@rustbot

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-bors

rust-borsBot commented May 12, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #156473) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPCDylan-DPC added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 16, 2026
let filtered_attrs = self.arena.alloc_from_iter(filtered_iter);

if filtered_attrs.is_empty() {
self.attrs.remove(&outer_hir_id.local_id);

@JonathanBrouwerJonathanBrouwerJun 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this code reachable with the early-return above?

View changes since the review

if filtered_attrs.is_empty() {
self.attrs.remove(&outer_hir_id.local_id);
} else {
self.attrs.insert(outer_hir_id.local_id, filtered_attrs);

@JonathanBrouwerJonathanBrouwerJun 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we overriding the attrs from outer_hir_id here?

View changes since the review

);

this.maybe_forward_track_caller(body.span, closure_hir_id, expr.hir_id);
this.forward_inline(body.span, closure_hir_id, expr.hir_id);

@JonathanBrouwerJonathanBrouwerJun 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some tests for this feature?

View changes since the review

@JonathanBrouwerJonathanBrouwerJun 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the lang team decision:

We talked about this in the lang call today. We want attributes like this to apply to "where the code is", i.e. to the poll function in this case. The wrapper function, on the other hand, should always be inlined.

Make sure your tests cover this.
I suspect the wrapper function is already marked as inline somewhere, if it is not could you or someone else open a separate PR that does this?

@rustbotrustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 21, 2026
@JonathanBrouwer

JonathanBrouwer commented Jun 21, 2026

Copy link
Copy Markdown
Member

Sorry for taking so long to review this PR! This PR fell of my radar, thanks @Dylan-DPC for fixing up the label so I saw it again

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

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)relnotesMarks issues that should be documented in the release notes of the next release.S-waiting-on-authorStatus: This is awaiting some action (such as code changes or more information) from the author.T-compilerRelevant 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

8 participants

@xacrimon@rustbot@rust-log-analyzer@JonathanBrouwer@bors@Enselic@Mark-Simulacrum@Dylan-DPC