Skip to content

Distinct .value of a non-Copy wrapper projects the inner type's first field: print(n.value) prints "", let k = n.value segfaults #1846

Closed

Description

@ehartford

Spec

§4.5 (distinct types are zero-cost wrappers; n.value reads the wrapped value, as behav_distinct_compat does for distinct i32).

Repro (main at 355c20b and impl-d75 at ad1bb55b alike)

type Name = distinct str
fn main:
    let n = "abc".clone() as Name
    print(n.value)
    let k = n.value
    print(k)

with run --debug-alloc: prints an empty line for print(n.value), then exits 139 (SIGSEGV) at print(k). With only the first print, it prints an empty line and leak count=0.

Expected

abc twice.

Cause (reading; not yet in lldb)

Sema types n.value as the inner str (a distinct type is a one-field struct { value: T }). MirLower's value path for a distinct .value is transparent (NK_FIELD_ACCESS in lower_expr returns lower_expr(base)), but the place path (lower_expr_place -> lower_field_access) projects field 0 of Name, whose LLVM type is the inner str struct {ptr, len} — so the "field" is the string's data pointer read as a whole str header. A non-Copy .value always takes the place path (auto-ref for print(&T), and D32's let k = place.field view binding). A distinct i32 never reaches it.

Found while fixing #1802 (D75 §4.5); n as &str / n as str are the working spellings.

Activity

  1. added a commit that references this issue on Sep 29, 2026
    fb6c6e4
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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions