Skip to content

Phase 5.3 — Conformance: simultaneous shared and mutable borrow is rejected #42

Description

@whoisclebs

Parent

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

Background

The aliasing rule is the core safety invariant: a place may have either N shared borrows or exactly one mutable borrow, never both simultaneously. Creating a &mut borrow while a & borrow is live — or vice versa — is a hard compile error. This test targets that exact conflict.

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

What already exists

  • compiler/paco-borrow/src/lib.rs — aliasing-rule check; emits a borrow-conflict diagnostic when & and &mut coexist.
  • compiler/paco-test-harness/src/lib.rs — golden test harness.

Scope

  • Create tests/conformance/phase_05/borrow_conflict/input.paco — a main that holds a &string reference and then tries to take a &mut string on the same binding while the shared borrow is still live.
  • Create tests/conformance/phase_05/borrow_conflict/expected.stderr with the aliasing-rule diagnostic, citing both the existing shared borrow and the conflicting mutable borrow.
  • Create tests/conformance/phase_05/borrow_conflict/flags.toml with kind = "fail" and feature_min = 5.

Acceptance Criteria

  • Compilation fails with a borrow-conflict diagnostic.
  • The diagnostic mentions both the existing shared borrow and the conflicting mutable borrow.
  • expected.stderr matches actual stderr byte-for-byte.
  • All previously passing conformance tests remain green.

Key files

  • tests/conformance/phase_05/borrow_conflict/ — new test directory
  • compiler/paco-borrow/src/lib.rs — aliasing-rule enforcement
  • 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