Skip to content

type_needs_drop returns true for *mut T during generic specialization re-check (is_copy simultaneously true) #898

Closed

Description

@ehartford

Evidence

Instrumenting the D32 field-move funnel and checking a program that
instantiates arena_vec_push[i32] (std.alloc's ArenaVec[T], ephemeral,
field arena: *mut Arena):

[d32] arm=consumed node=8036 field_ty=113 resolved=113 kind=13 copy=1 name=*mut Arena

kind 13 = TY_PTR, is_copy = 1 — yet the branch is gated on
type_needs_drop(field_ty) != 0, so type_needs_drop(*mut Arena)
returned TRUE in the specialization re-check of the generic body. In the
ordinary (non-specialization) pass the same query returns false — a local
copy of the same fn checked standalone does not trip the gate.

Repro

use std.alloc
fn main:
    var arena = arena_new(64)
    var xs: ArenaVec[i32] = ArenaVec { arena: &raw mut arena as *mut Arena, ptr: 0 as *mut i32, len_value: 0, cap_value: 0 }
    let xsp = &raw mut xs as *mut ArenaVec[i32]
    unsafe:
        arena_vec_push(xsp, 10)

Before the D32 funnel was re-gated on is_copy this produced a spurious
"a field never moves out implicitly" error inside <embedded-std>/std/alloc.w
(let arena = (*xs).arena). The D32 gate now uses is_copy == 0 as the
durable move discriminator, so the user-visible symptom is fixed — but the
needs_drop/is_copy disagreement for pointer types under substitution
remains and any other consumer of type_needs_drop in a specialization
context may mis-schedule drops for Copy pointer fields.

Expected

type_needs_drop(*mut T) is false in every checking context.

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): not reproduced at the surface. The evidence here came from instrumenting the D32 field-move funnel; no observable program behavior was recorded, and a program instantiating ArenaVec[i32] (std.alloc) builds and runs today. Confirming it needs the same instrumentation or an lldb breakpoint on Sema.type_needs_drop for a TY_PTR argument during specialization re-check, which is a debugging session, not triage. Left open for whoever takes the D32 funnel next.

  2. added this to the post-v0.16.0 milestone on Oct 28, 2026
  3. ehartford commented on Nov 18, 2026

    @ehartford
    ContributorAuthor

    Not a ruling: this needs a debugger session on Sema.type_needs_drop for a TY_PTR argument during specialization re-check, which is mine. Label removed.

  4. ehartford commented on Nov 21, 2026

    @ehartford
    ContributorAuthor

    Root cause, for the record: type_has_drop_impl named the pointee of a pointer type (get_type_name), so in a specialization *mut T read as having its pointee's Drop impl and type_needs_drop answered true. The guard at the top of type_has_drop_impl (added for #1492: a reference or raw pointer owns nothing) removed that for every caller. The issue's own repro no longer exists (ArenaVec is gone from std.alloc), so behav_898_pointer_field_in_specialization_owns_nothing (#3501) reads a *mut Loud field twice inside a generic body at two instantiations: the pointee drops once and the debug allocator reports no leak.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions