Issue #1215: Borrow checker: three wrong diagnostics found while writing the ownership guide

Open and answer this issue on GitHub.

ready · opened 2026-11-03 · updated 2026-11-03 · 0 comments

Found by the builder of the guide chapter guide/ownership.md (docs lane, d1). Each one is a defect: the specification (Part I 6.6) says otherwise.

Probes

  1. A struct built from an owned String and an int is refused, although nothing is lent:
    struct Badge { owner: String, number: int }
    fn badge_for(name: String, n: int) -> Badge { return Badge { owner: name, number: n } }
    // called with "grace".to_uppercase()

    The compiler refuses it with NK2302, “hands back a view of n”, even though n is an int. Without the int field the program runs.

  2. A change after a kept view gives the wrong code:
    let mut y = "short"; let r = longest(x, y); y.push_str("er"); println(r)

    The compiler gives NK2105, “longest keeps it”. The right code is NK2305, which is what it gives with "short".to_uppercase().

  3. fn add_guest(names: Vec[String]) { names.push(..) } gets NK1138, which is correct. A second error, NK2105, then appears at the caller and names Vec[ref String]. That second error should not be there.

To build

Also found, for the specification lane (#1213, v1)

Back to Open Issues