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
A view through ?? loses its temporary's origin: (read_file(p) ?? "").trim() is accepted and reads freed memory (§21.1, D22) #2659
Spec: §21.1 (a view of a temporary), D22 ("Option, Result, patterns, ?, ?? and eliminators are transparent to view origins").
use std.fs
fn main:
let p = "some/file.txt"
let b = (read_file(p) ?? "").trim() // accepted
let u = read_file(p).unwrap().trim() // refused: "`u` binds a view into a temporary `str` that is freed when this statement ends (§21.1)"
b is a view into the str that read_file(p) ?? "" produced, a temporary freed at the end of the statement, exactly as u's is. The unwrap() spelling is refused and the ?? spelling is accepted, and b then reads freed memory. In a program that later builds a list (&["x", b], the argv for std.process.run) the bytes come back as zeros: a 141-byte title arrived at gh as 142 empty arguments ("accepts at most 1 arg(s), received 142").
$ with analyze view4.w 'explain:origin:main:b'
binding `b` bind at view4.w:4: origins=[] storage=[] deps=[]
The origin is lost at ??: the tool reports no origin where unwrap() keeps it.
Expected: ?? carries the origin of the value it yields (D22), so b is refused with the same §21.1 diagnostic as u. Workaround: bind the ?? result first (let a = read_file(p) ?? "" then a.trim()), which is correct today.
Activity
Sema: a view into a parenthesized temporary is refused like any other (…
ehartford commentedon Oct 26, 2026
Fixed on main by 9fcb78a (stack #2743, battery GREEN on its top ddb68e8: behavior-tests 1949/1949, gate, uat and battery-checks green).
Sema: a binding or inferred return of a view into a statement tempora…
Sema: a binding or inferred return of a view into a statement tempora…