Skip to content

Diagnostics: coerced-borrow ephemeral return rejected with wrong message (soundness hole verified closed; pin with fixtures) #626

Closed

Description

@ehartford

Summary

fn f() -> StrView: let owned = ...; return StrView { s: owned } — returning an ephemeral whose &str field borrows an OWNED LOCAL — passes check; the caller dangles. collect_expr_view_deps (SemaCheck.w:7640-7652) records deps only for TY_REF-typed idents and explicit & borrows; the owned-str → &str field coercion produces no dep, so check_returned_ephemeral_value_origins sees zero origins.

Spec

§5.2 ephemerality propagation / §21.1 Rule 6-adjacent: a view's origin set must include owned locals feeding coerced borrows; a returned view whose origin is a dying local is rejected.

Found

During the #600 blast-radius sweep (probe p7), 2026-07-03.

Activity

  1. added a commit that references this issue on Jul 4, 2026
  2. ehartford commented on Jul 4, 2026

    @ehartford
    ContributorAuthor

    BDFL ruling (2026-07-04): downgraded soundness → diagnostics. Verified on HEAD: the explicit-borrow escape gets the correct 'returned ephemeral value may outlive its origin' error, and the coerced form is rejected (with a wrong 'return type mismatch' message). Remaining work: record view deps for the owned→&str field coercion so the RIGHT error fires, and pin every escape shape with compile-error fixtures so the closure can't silently regress.

  3. changed the title [-]Returned ephemeral wrapping a borrow of an OWNED local escapes view-dep tracking (dangling read)[/-] [+]Diagnostics: coerced-borrow ephemeral return rejected with wrong message (soundness hole verified closed; pin with fixtures)[/+] on Jul 4, 2026
  4. ehartford commented on Jul 5, 2026

    @ehartford
    ContributorAuthor

    Fixed in 5289264. An owned local coerced into a reference field now records a borrow origin on the struct literal, so a returned/stored view over a dying local is rejected (was a silent soundness hole: check passed, caller dangled). Params and static literals stay legal. Fixpoint + full suite green; 3 fixtures pin the escape shapes.

  5. added a commit that references this issue on Jul 5, 2026
    5289264
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions