Skip to content

Skip long lived pin facts for unpin places#5

Merged
frank-king merged 2 commits intofrank-king:feature/pin-borrowckfrom
P8L1:skip-long-lived-pin-facts-for-unpin-places
May 3, 2026
Merged

Skip long lived pin facts for unpin places#5
frank-king merged 2 commits intofrank-king:feature/pin-borrowckfrom
P8L1:skip-long-lived-pin-facts-for-unpin-places

Conversation

@P8L1
Copy link
Copy Markdown

@P8L1 P8L1 commented May 2, 2026

This fixes the borrowck side of the Unpin behaviour for &pin.

The typeck check already accepts direct &pin borrows when the target type is known to be Unpin, but the Pins dataflow analysis still generated long-lived pinned-borrow facts for those borrows.

This now suppresses long-lived pin facts at their source when the original pinned place type is known to be Unpin. The decision is tied to the original pinned place, not the later accessed place, so projected accesses are not accidentally made too permissive.

Tests cover expired &pin borrows of Unpin places, generic T: Unpin places, existing !Unpin behaviour, and projection cases where a pinned parent still blocks moving or mutably borrowing a conflicting field.

@P8L1 P8L1 force-pushed the skip-long-lived-pin-facts-for-unpin-places branch from 59822e7 to 3b155c2 Compare May 2, 2026 12:10
Comment thread compiler/rustc_borrowck/src/lib.rs Outdated
Remove the now-unnecessary helper method and access state.pinned_borrows directly.
@frank-king frank-king merged commit be61203 into frank-king:feature/pin-borrowck May 3, 2026
2 of 11 checks passed

fn baz(mut x: Foo, mut y: Foo) {
{
let _x = &pin mut x;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Could you please also add a test for ref pin patterns? (And similarly, tests that involve both &pin borrows and moves (or &mut borrows) should also be tested together with ref pin patterns).

{
    let ref pin mut _x = x;
}
let _x = &mut x; //~ ERROR ...
let _x = x; //~ ERROR ...

Previous tests for pin patterns focused on pin projections only, but didn't test whether it works well with the borrowck stuff (Ideally, &pin borrows should be equivalent with ref pin patterns, just like the normal borrows &mut with ref mut patterns). That's the remaining TODOs related to pin patterns.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, added the requested ref pin pattern coverage.

This required a small MIR build change as well: with only the new tests kept and the implementation files reverted, the new ref pin diagnostics were missing. So the implementation now lowers ref pin mut / ref pin const patterns to BorrowKind::Pinned(..., PinBorrowKind::Persistent), while preserving the old behavior for ordinary non-pinned ref / ref mut patterns.

Added coverage for:

  • ref pin mut followed by later &mut
  • ref pin mut followed by later move
  • ref pin const followed by later &mut
  • ref pin const followed by later move
  • pinned projection cases
  • pinned parent / field cases
  • Unpin vs !Unpin behavior

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I opened this as a follow-up PR since #5 was already merged:

#6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants