Skip to content

ty_utils: AsyncDropGlueCtor allowlist misses UnsafeBinder (and ty::Pat) #611

Description

@SebTardif

Bug

When resolving async_drop_in_place (LangItem::AsyncDropInPlace), nontrivial async drop glue requires the type kind to be in an allowlist. That list includes Closure, CoroutineClosure, Coroutine, Tuple, Adt, Dynamic, Array, and Slice, but not UnsafeBinder or ty::Pat.

Sync DropGlue resolution for the same structural cases does allow UnsafeBinder (and still omits Pat).

So for an UnsafeBinder type with needs_async_drop == true, instance resolution returns Ok(None) instead of building AsyncDropGlueCtor, while sync drop glue would accept the binder.

needs_drop_components / async drop component logic treats UnsafeBinder as a component type (Ok(smallvec![ty])) and peels Pat to its inner type, so the allowlist is inconsistent with the needs-drop decomposition.

Affected code

compiler/rustc_ty_utils/src/instance.rs (resolve_instance_raw, AsyncDropInPlace branch)

Impact

Wrong/missing async-drop instance for unsafe-binder types that need async drop (I-wrong), vs sync drop. Unstable async_drop / unsafe_binder interaction.

ty::Pat note (latent): Pattern types currently focus on integer ranges (Copy, typically no drop). When Pat can wrap drop-bearing inners, both DropGlue and AsyncDropGlueCtor omit Pat from the nontrivial allowlist while needs_drop can be true via peeled components. Prefer adding Pat alongside UnsafeBinder for consistency with Array/Slice compound handling, or document intentional deferral.

Origin

Lines Commit Date Author
AsyncDropInPlace allowlist 80c0b7e90fd0 / async-drop shim work 2024-04-17 Daria Sukhonina
UnsafeBinder added to DropGlue only later UnsafeBinder wiring

Suggested fix

Add | ty::UnsafeBinder(..) to the AsyncDropGlueCtor nontrivial match (mirror DropGlue). Optionally add | ty::Pat(..) to both DropGlue and AsyncDropGlueCtor allowlists for consistency with component peeling.

Related

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemType systemI-wrongWrong result or data corruptionP-mediumMedium impact: affects specific usage patternsbugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions