Skip to content

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

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

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

Conversation

@frank-king
Copy link
Copy Markdown
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
    } // now the pinned reference expires
    let _x = &mut x; //~ ERROR cannot borrow `x` as mutable because it is pinned
    let _x = x; //~ ERROR cannot move out of `x` 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)

Unresolved questions

@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
@rust-log-analyzer

This comment has been minimized.

@frank-king frank-king force-pushed the feature/pin-borrowck branch from f6b714b to 46c66aa Compare April 17, 2026 03:07
@rust-log-analyzer

This comment has been minimized.

@P8L1

This comment has been minimized.

@P8L1

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@P8L1

This comment has been minimized.

@P8L1

This comment was marked as resolved.

@frank-king
Copy link
Copy Markdown
Contributor Author

I think about whether to allow the &pin borrows of the generic ADTs without #[pin_v2] is under further consideration, so I added it as an unresolved question that helps the reviewers from the lang-team or the types-team to make decisions.

@rust-log-analyzer

This comment has been minimized.

@frank-king
Copy link
Copy Markdown
Contributor Author

Let me self-review the whole PR carefully before marking it ready for review.

@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_middle/src/mir/syntax.rs Outdated
@rust-bors

This comment has been minimized.

@frank-king frank-king force-pushed the feature/pin-borrowck branch from a72c987 to 9fe2f02 Compare May 4, 2026 02:48
@P8L1

This comment has been minimized.

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.

4 participants