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
Codegen: r as str with r: &Name (a distinct str) casts the reference, not the string — prints garbage #1782
§4.5 (distinct types: zero-cost wrappers), §3.7 (a cast through a reference reads what it names).
Repro
type Name = distinct str
fn show(n: &Name): print(n as str)
fn main:
let s = "abc".clone()
let n = s as Name
show(n)
Actual
Base stage1 (76cf0bf) and batch2-ownership's stage1: prints a garbage byte, debug-alloc: leak count=0.
Expected
abc.
Cause (reading, not yet in lldb)
MirLower.lower_cast reads through a reference only when the pointee is str, an array or a slice (r as []u8 with r: &str, §3.7). A &Name whose pointee is a distinct str takes the other path and casts the reference value (a pointer) to the string header.
Related, same shape: let n = s as Name lowers as _6 = cast(move _1 as ty239) with no reset, and both _1 and _5 get scope-exit drops; the distinct type's drop glue is what decides whether that is a double free. Found while fixing #1719 (a cast reads its source); not changed there.
Activity
MirLower: a cast through a reference reads what it names, through a d…
MirLower: a cast through a reference reads what it names, through a d…
MirLower: a cast through a reference reads what it names, through a d…