Skip to content

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

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

Implement borrowck for &pin mut|const $place#153693
frank-king wants to merge 7 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.

P8L1 added 2 commits May 3, 2026 21:49
Remove the now-unnecessary helper method and access state.pinned_borrows directly.
@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
Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-miri failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

}

#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, TyEncodable, TyDecodable)]
#[derive(Hash, HashStable)]
Copy link
Copy Markdown

@P8L1 P8L1 May 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they renamed it, should it not be 'StableHash' instead of 'HashStable'?

Refer to: e7d28d3

I made a PR to fix it: frank-king#7

View changes since the review

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