You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a tracking issue for work on pin ergonomics.
The feature gate for the issue is #![feature(pin_ergonomics)].
Design sketch
The basic pin projection rules that we're working toward are:
Alternative B:
If T: Unpin, &pin mut T and &mut T coerce to each other.
If a struct, enum, or union(?) defining a type T is annotated with #[pin_v2] (todo bikeshedding), then:
Projection of &pin mut T to &pin mut T.U is allowed.
If T: Drop , the Drop impl must use fn drop(&pin mut self).
No manual impls of Unpin are allowed on T.
The user must ensure that, given a pinned reference to T, the pinning contract is upheld for all ?Unpin fields of T.
(The rules apply likewise for &pin const T.)
Beyond pin projection, the basic overall idea of pin ergonomics is that &pin mut T (and &pin const T) should be integrated in the same sense as &mut T, in that reborrowing works, autoref works, corresponding binding modes exist, and that the borrow checker will track and ensure that once a &pin mut T is taken (even if no longer live) that we can't later get a &mut T or move T.
Alternative A
The original proposal, now labeled Alternative A, was:
If T: Unpin, &pin mut T and &mut T coerce to each other.
If T: Drop + !Unpin, require the Drop impl for T to use fn drop(&pin mut self).
Projection of &pin mut T to &pin mut T.U is allowed if either T: !Unpin or U: Unpin.
These rules are factored differently (using coercions (see here) and the fact that we haven't stabilized negative impls yet), but have the same effect as the rules in Niko's otherwise similar MinPin proposal.
About tracking issues
Tracking issues are used to record the overall progress of implementation. They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions. A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature. Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
Approve as lang experiment.
We accepted this experiment in the 2024-09-18 lang triage meeting.
Apparently this gives special semantics to the Unpin trait (at least, the compiler usesis_unpin checks in &pin handling). That is a safe trait and hence cannot be deeply semantically meaningful. Is this coherent?
Update: fn drop(&pin mut self) sugar has now landed in #156452.
This implements fn drop(&pin mut self) as sugar for Drop::pin_drop: resolver performs the effective pin_drop lookup, and AST lowering validates that the sugar is being used for the actual Drop lang trait before lowering accepted cases to pin_drop.
I see there are a lot of pin_v2 issues. For tracking, I just want to get more attention on #153693, which forbids &pin borrows for ADTs without #[pin_v2], and I have a strong suspicion it will solve some of the current issues. Although it seems to me like the PR is dead, it has been waiting on review for 1 month now.
Activity
[-]Tracking Issue for pin ergonomics[/-][+]Tracking issue for pin ergonomics[/+]traviscross commentedon Sep 19, 2024
We accepted this experiment in the 2024-09-18 lang triage meeting.
Thanks to @eholk for pushing this forward.
Rollup merge of rust-lang#130526 - eholk:pin-reborrow, r=compiler-errors
Unrolled build for rust-lang#130526
Auto merge of rust-lang#130633 - eholk:pin-reborrow-self, r=compiler-…
Rollup merge of rust-lang#130633 - eholk:pin-reborrow-self, r=compile…
Unrolled build for rust-lang#130633
Rollup merge of rust-lang#130635 - eholk:pin-reborrow-sugar, r=compil…
50 remaining items
Rollup merge of rust-lang#156452 - P8L1:implement-pin-drop-sugar-upst…
Rollup merge of rust-lang#156452 - P8L1:implement-pin-drop-sugar-upst…
Rollup merge of rust-lang#156452 - P8L1:implement-pin-drop-sugar-upst…
Rollup merge of rust-lang#156452 - P8L1:implement-pin-drop-sugar-upst…
Unrolled build for #156452
P8L1 commentedon May 16, 2026
Update:
fn drop(&pin mut self)sugar has now landed in #156452.This implements
fn drop(&pin mut self)as sugar forDrop::pin_drop: resolver performs the effectivepin_droplookup, and AST lowering validates that the sugar is being used for the actualDroplang trait before lowering accepted cases topin_drop.#[pin_v2]incorrectly handles packed structs. #157011#[repr(packed)]field breaksPinwithout#[pin_v2]#157615Rollup merge of rust-lang#157542 - Dnreikronos:pin_v2_ban_repr_packed…
Unrolled build for #157542
ref pin mutpattern unsoundly allows pin-projecting arbitrary types #157634P8L1 commentedon Jun 9, 2026
I see there are a lot of pin_v2 issues. For tracking, I just want to get more attention on #153693, which forbids &pin borrows for ADTs without #[pin_v2], and I have a strong suspicion it will solve some of the current issues. Although it seems to me like the PR is dead, it has been waiting on review for 1 month now.
Auto merge of #148397 - frank-king:feature/pin-pattern, r=Nadrieril,t…
Rollup merge of rust-lang#161794 - fmease:fix-weak-pin, r=adwinwhite
Unrolled build for #161794 in rollup 161970