You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Distinct .value of a non-Copy wrapper projects the inner type's first field: print(n.value) prints "", let k = n.value segfaults #1846
§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
Codegen: a distinct type's `.value` is the wrapped value's own place,…