Skip to content

Fix async drop glue for Box<T>#156067

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
P8L1:async-drop-box-fix
Jun 10, 2026
Merged

Fix async drop glue for Box<T>#156067
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
P8L1:async-drop-box-fix

Conversation

@P8L1

@P8L1 P8L1 commented May 1, 2026

Copy link
Copy Markdown
Contributor

View all comments

Fixes #143658.

This fixes async drop behavior for boxed values so that async drop glue reaches the boxed value’s async destructor in async drop context.

The change updates async-drop needs-drop analysis so Box<T> is handled specially for async drop by considering the boxed pointee and allocator when deciding whether async drop glue is needed.

This PR intentionally does not change the broader AsyncDrop design. It only fixes behavior under the existing #![feature(async_drop)] implementation.

Reviewer notes:

  • async-drop-box-allocator.rs already covers async-dropping the allocator of a Box; this PR adds distinct coverage for the boxed value itself.
  • Boxed dyn pointees are intentionally not pulled into this fix, preserving existing dynamic async-drop limitations.
  • The change is isolated to async drop analysis; sync needs_drop behavior is unchanged.

@rustbot label F-async_drop

@rustbot rustbot added 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 May 1, 2026
@rustbot

rustbot commented May 1, 2026

Copy link
Copy Markdown
Collaborator

r? @oli-obk

rustbot has assigned @oli-obk.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 21 candidates

@P8L1

This comment was marked as resolved.

@rust-log-analyzer

This comment has been minimized.

@Kivooeo Kivooeo closed this May 1, 2026
@Kivooeo Kivooeo reopened this May 1, 2026
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 1, 2026
@oli-obk

This comment was marked as resolved.

@P8L1

This comment was marked as resolved.

@oli-obk

oli-obk commented May 3, 2026

Copy link
Copy Markdown
Contributor

oof turns out I didn't see #145316 for 9 months. Gonna review that one first

@oli-obk oli-obk added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label May 3, 2026
@P8L1

P8L1 commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

oof turns out I didn't see #145316 for 9 months. Gonna review that one first

LMAO Ok gl

@oli-obk oli-obk removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 5, 2026
@P8L1

P8L1 commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

@oli-obk can I close this?

@oli-obk

oli-obk commented May 6, 2026

Copy link
Copy Markdown
Contributor

I'd like to land the sized-only version first. I don't know if the other PR's solution is different from yours. I'll need to compare and figure out whether either solution is one to merge

@rustbot rustbot added the F-async_drop `#![feature(async_drop)]` label May 22, 2026
@oli-obk oli-obk removed the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Jun 8, 2026

@oli-obk oli-obk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we have tests for dyn? If not, please add one with a note that it needs fixing

View changes since this review

Comment thread compiler/rustc_ty_utils/src/needs_drop.rs Outdated
Comment thread compiler/rustc_ty_utils/src/needs_drop.rs Outdated
Comment thread compiler/rustc_ty_utils/src/needs_drop.rs Outdated
@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 8, 2026
@rustbot

rustbot commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

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

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@P8L1 P8L1 force-pushed the async-drop-box-fix branch from 39bb468 to d8aad82 Compare June 8, 2026 21:47
@rustbot

rustbot commented Jun 8, 2026

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.

@P8L1

P8L1 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot 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 8, 2026
@P8L1

P8L1 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@bors squash

@rust-bors

This comment has been minimized.

* Fix async drop glue for Box<T>
* Adress reviewer concerns
* Address more concerns
@rust-bors

rust-bors Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🔨 3 commits were squashed into 2bc5e90.

@rust-bors rust-bors Bot force-pushed the async-drop-box-fix branch from 56222cb to 2bc5e90 Compare June 9, 2026 11:24
@P8L1 P8L1 requested a review from oli-obk June 9, 2026 11:25
@oli-obk

oli-obk commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

😅 right that works

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 2bc5e90 has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 9, 2026
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jun 9, 2026
Fix async drop glue for Box<T>

Fixes rust-lang#143658.

This fixes async drop behavior for boxed values so that async drop glue reaches the boxed value’s async destructor in async drop context.

The change updates async-drop needs-drop analysis so `Box<T>` is handled specially for async drop by considering the boxed pointee and allocator when deciding whether async drop glue is needed.

This PR intentionally does not change the broader AsyncDrop design. It only fixes behavior under the existing `#![feature(async_drop)]` implementation.

Reviewer notes:
- `async-drop-box-allocator.rs` already covers async-dropping the allocator of a `Box`; this PR adds distinct coverage for the boxed value itself.
- Boxed dyn pointees are intentionally not pulled into this fix, preserving existing dynamic async-drop limitations.
- The change is isolated to async drop analysis; sync `needs_drop` behavior is unchanged.

@rustbot label F-async_drop
rust-bors Bot pushed a commit that referenced this pull request Jun 9, 2026
Rollup of 10 pull requests

Successful merges:

 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jun 9, 2026
Fix async drop glue for Box<T>

Fixes rust-lang#143658.

This fixes async drop behavior for boxed values so that async drop glue reaches the boxed value’s async destructor in async drop context.

The change updates async-drop needs-drop analysis so `Box<T>` is handled specially for async drop by considering the boxed pointee and allocator when deciding whether async drop glue is needed.

This PR intentionally does not change the broader AsyncDrop design. It only fixes behavior under the existing `#![feature(async_drop)]` implementation.

Reviewer notes:
- `async-drop-box-allocator.rs` already covers async-dropping the allocator of a `Box`; this PR adds distinct coverage for the boxed value itself.
- Boxed dyn pointees are intentionally not pulled into this fix, preserving existing dynamic async-drop limitations.
- The change is isolated to async drop analysis; sync `needs_drop` behavior is unchanged.

@rustbot label F-async_drop
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 9, 2026
Fix async drop glue for Box<T>

Fixes rust-lang#143658.

This fixes async drop behavior for boxed values so that async drop glue reaches the boxed value’s async destructor in async drop context.

The change updates async-drop needs-drop analysis so `Box<T>` is handled specially for async drop by considering the boxed pointee and allocator when deciding whether async drop glue is needed.

This PR intentionally does not change the broader AsyncDrop design. It only fixes behavior under the existing `#![feature(async_drop)]` implementation.

Reviewer notes:
- `async-drop-box-allocator.rs` already covers async-dropping the allocator of a `Box`; this PR adds distinct coverage for the boxed value itself.
- Boxed dyn pointees are intentionally not pulled into this fix, preserving existing dynamic async-drop limitations.
- The change is isolated to async drop analysis; sync `needs_drop` behavior is unchanged.

@rustbot label F-async_drop
rust-bors Bot pushed a commit that referenced this pull request Jun 9, 2026
Rollup of 18 pull requests

Successful merges:

 - #152852 (Remove driver_lint_caps)
 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
rust-bors Bot pushed a commit that referenced this pull request Jun 9, 2026
Rollup of 17 pull requests

Successful merges:

 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Rollup of 17 pull requests

Successful merges:

 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Rollup of 17 pull requests

Successful merges:

 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Rollup of 17 pull requests

Successful merges:

 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Rollup of 17 pull requests

Successful merges:

 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Rollup of 17 pull requests



Successful merges:

 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Rollup of 17 pull requests



Successful merges:

 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Rollup of 17 pull requests



Successful merges:

 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
@rust-bors rust-bors Bot merged commit 9c291fb into rust-lang:main Jun 10, 2026
12 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 10, 2026
rust-timer added a commit that referenced this pull request Jun 10, 2026
Rollup merge of #156067 - P8L1:async-drop-box-fix, r=oli-obk

Fix async drop glue for Box<T>

Fixes #143658.

This fixes async drop behavior for boxed values so that async drop glue reaches the boxed value’s async destructor in async drop context.

The change updates async-drop needs-drop analysis so `Box<T>` is handled specially for async drop by considering the boxed pointee and allocator when deciding whether async drop glue is needed.

This PR intentionally does not change the broader AsyncDrop design. It only fixes behavior under the existing `#![feature(async_drop)]` implementation.

Reviewer notes:
- `async-drop-box-allocator.rs` already covers async-dropping the allocator of a `Box`; this PR adds distinct coverage for the boxed value itself.
- Boxed dyn pointees are intentionally not pulled into this fix, preserving existing dynamic async-drop limitations.
- The change is isolated to async drop analysis; sync `needs_drop` behavior is unchanged.

@rustbot label F-async_drop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-async_drop `#![feature(async_drop)]` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

AsyncDrop not called when type is inside Box

5 participants