Skip to content

Phase 5.4 — Conformance: borrow that outlives its owner is rejected #43

Description

@whoisclebs

Parent

Part of #7 (Phase 5: Implement borrowing and lifetime inference).

Background

A reference must not outlive the value it points to. When a borrow is stored in a variable and the owner goes out of scope first, the reference becomes a dangling pointer. The lifetime checker must detect this and reject the program before it reaches codegen.

Spec reference: docs/design/spec.md §3, ADR 0001 · Crate: paco-borrow

What already exists

  • compiler/paco-borrow/src/lib.rs — lifetime scope tracking; detects borrows that escape their owner's scope.
  • compiler/paco-test-harness/src/lib.rs — golden test harness.

Scope

  • Create tests/conformance/phase_05/borrow_outlives_owner/input.paco — a main that creates a reference to a value defined in an inner block, then uses the reference after the inner block ends (owner dropped).
  • Create tests/conformance/phase_05/borrow_outlives_owner/expected.stderr with the lifetime error and span on the escaping reference.
  • Create tests/conformance/phase_05/borrow_outlives_owner/flags.toml with kind = "fail" and feature_min = 5.

Acceptance Criteria

  • Compilation fails with a lifetime error.
  • Span points at the use of the reference after the owner's scope ends.
  • expected.stderr matches actual stderr byte-for-byte.
  • All previously passing conformance tests remain green.

Key files

  • tests/conformance/phase_05/borrow_outlives_owner/ — new test directory
  • compiler/paco-borrow/src/lib.rs — escape detection
  • compiler/paco-driver/tests/conformance.rs — conformance runner

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/analysisType system, trait solver, borrow checker, pattern matchingenhancementNew feature or requestphase/5Phase 5: borrowing and lifetime inferencestatus/readyAll dependencies met — ready to implement

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions