Open and answer this issue on GitHub.
ready · opened 2026-11-02 · updated 2026-11-02 · 0 comments
Found by b37 (#1152).
struct L { n: i64 }
struct W { own: ref L, k: i64 }
fn make() -> W {
let xs = [L { n: 3 }]
let first: ref L = xs[0]
return W { own: first, k: 1 }
}
The checker refuses nothing, and rustc says “cannot return value referencing local variable”. A name: ref String field given a local behaves the same, and so does the unfixed compiler. The view outlives the local it points into. No caller’s keep can hold it, because the local is gone when make returns. So by the tether rules (Part III, NK2303) it is a view escaping its source, and the checker should refuse it with an NK message at the return, not leave it to rustc.
To build:
ref field views a local of the returning function, or a part of one. Use the existing code for a returned bare view of a local, if there is one; otherwise ask the supervisor for a code from its block.tests/compiler/tests/ref_field_outlives_local.nika with its .stderr. This is the refusal test #1152 step 1 asked for.