Skip to content

Implement borrowck for &pin mut|const $place#153693

Draft
frank-king wants to merge 5 commits intorust-lang:mainfrom
frank-king:feature/pin-borrowck
Draft

Implement borrowck for &pin mut|const $place#153693
frank-king wants to merge 5 commits intorust-lang:mainfrom
frank-king:feature/pin-borrowck

Conversation

@frank-king
Copy link
Contributor

@frank-king frank-king commented Mar 11, 2026

Part of Pin Ergonomics.

This forbids places to be moved or mutably borrowed ever since they are pinned until they are reassigned (even after the pinned borrows themselves expire).

#![feature(pin_ergnonmics)]
#![allow(incomplete_features)]

#[pin_v2]
struct Foo;

fn foo(mut x: Foo) {
    let _x = &pin mut x; // x is pinned
    drop(_x); // now the pinned reference expires
    let _x = x; //~ ERROR cannot move out of `x` because it is pinned
    let _x = &mut x; //~ ERROR cannot borrow `x` as mutable because it is pinned
    
    x = Foo; // x is reassigned
    let _x = &mut x; // ok because x is reassigned and not pinned yet
}

Tasks:

  • Add Pins dataflow analysis
  • Improve the diagnostics of pinning errors
  • Test pin pattern matching
  • Forbid &pin borrows for ADTs without #[pin_v2] (for soundness concerns)

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants