Repository navigation
Open
Labels
B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-unsafe_pinned`#![feature(unsafe_pinned)]``#![feature(unsafe_pinned)]`T-langRelevant to the language teamRelevant to the language teamT-opsemRelevant to the opsem teamRelevant to the opsem team
Description
This is a tracking issue for RFC 3467: UnsafePinned.
The feature gate for the issue is #![feature(unsafe_pinned)].
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
- Accept an RFC.
- Implement.
- Initial
UnsafePinnedimplementation [Part 1: Libs] #137043 - UnsafePinned: also include the effects of UnsafeCell #140638
- Initial
UnsafePinnedimplementation [Part 2: Lowering] #139896 - UnsafePinned: update get() docs and signature to allow shared mutation #142162
- UnsafePinned: implement opsem effects of UnsafeUnpin #151365
- Initial
- Add documentation to the dev guide.
- See the instructions.
- Add documentation to the reference.
- See the instructions.
- Stabilize.
Unresolved Questions
- Do we want to bikeshed the name further before stabilization?
- Should
&UnsafePinnedpermit mutation or not? Also see Decide what to do aboutUnsafePinnedand safePin::as_ref#137750- This was decided via champion decision and meeting consensus in a shorthanded meeting; this item will need to receive attention in the stabilization report.
- Which of
Send,Sync,Copy,Cloneshould this type implement under which conditions? Also see this. - Do we want to stabilize
Freezefirst? And what about the equivalent trait for&mutaliasing (UnpinUnsafein the RFC)? - Do we need all these
getmethods? - UnsafePinned should provide the same guarantee layouts as UnsafeCell #156163
- What about variance?
Related
Implementation history
TODO.
Reacted by Xinyu Yang, teor and ArsenalAlex108
Reacted by José Luis Cruz
Metadata
Metadata
Assignees
Labels
B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-unsafe_pinned`#![feature(unsafe_pinned)]``#![feature(unsafe_pinned)]`T-langRelevant to the language teamRelevant to the language teamT-opsemRelevant to the opsem teamRelevant to the opsem team
Activity
RalfJung commentedon Aug 2, 2024
Turns out the existing hack that attempts to make self-referential async lowering sound is incomplete, and we most likely need
UnsafePinnedto make it actually sound.RalfJung commentedon Aug 20, 2024
In the RFC we had the question whether
UnsafePinnedshould also act like anUnsafeCell. I am now fairly sure that the answer is "yes, it must". The reason is this: due toPin::derefbeing safe, it is at any moment possible to create a shared reference to a future that is halted at a suspension point. If there is noUnsafeCell, this acts like a read of the entire future data, and that read conflicts with mutable references that the future may hold to its own data. This is not a necessary property of aliasing with mutable reference, but it is a necessary consequence of the decision thatPin::derefshould be safe.Cc @rust-lang/opsem
Auto merge of rust-lang#129313 - RalfJung:coroutine-niches, r=compile…
Auto merge of rust-lang#129313 - RalfJung:coroutine-niches, r=compile…
Auto merge of rust-lang#129313 - RalfJung:coroutine-niches, r=compile…
Auto merge of rust-lang#129313 - RalfJung:coroutine-niches, r=compile…
Auto merge of #129313 - RalfJung:coroutine-niches, r=compiler-errors
Auto merge of #129313 - RalfJung:coroutine-niches, r=compiler-errors
26 remaining items
Unrolled build for #145593
Rollup merge of rust-lang#145593 - RalfJung:unsafepinned-raw_get, r=M…
jdahlstrom commentedon Oct 25, 2025
If
get_mut_uncheckedandget_mut_pinnedare someday stabilized, yes, they should absolutely be renamed toget_unchecked_mutandget_pinned_mutfor consistency.RalfJung commentedon Jan 19, 2026
Another case of UB caused by unintended uniqueness in futures: rust-lang/miri#4809.
It's really high time that we fix the
asynclowering to useUnsafePinnedto finally properly tackle this ancient I-unsound issue.Rollup merge of rust-lang#151365 - RalfJung:unsafe-unpin-opsem, r=Box…
Rollup merge of rust-lang#151365 - RalfJung:unsafe-unpin-opsem, r=Box…
Unrolled build for #151365
Rollup merge of #151365 - RalfJung:unsafe-unpin-opsem, r=BoxyUwU
Rollup merge of rust-lang#152646 - zachs18:unsafeunpin-marker-impls-p…
Unrolled build for #152646
jacobsa commentedon May 4, 2026
Hi, question about what seems to be an omission in the documentation: should
UnsafePinnedmake the same layout guarantees asUnsafeCell? I assume that's more or less intended, but it would be good to be explicit (and in any case I'd still be happy with an answer here).For the record: the reason I care is that I'm pretty sure I need this guarantee in order to be able to do in-place initialization of the
Twithin anUnsafePinned<T>, using e.g. Crubit'sctorcrate, at least in order for it to approach being ergonomic.RalfJung commentedon May 4, 2026
Yeah it would make sense to give it the same layout guarantees.
nbdd0121 commentedon Jul 21, 2026
The change that make
UnsafePinnedalso wrapUnsafeCellchanges the variance ofUnsafePinned. In 1.87/1.88UnsafePinnedis covariant, while 1.89+ it becomes invariant. This makes it much more limiting thanPhantomPinnedas that doesn't change the variance.For code that just needs pinning for self-reference and not for mutation, this is very limiting.
RalfJung commentedon Jul 21, 2026
Oh yeah I didn't think about variance at all.
It would seem a bit odd if UnsafePinned becomes the way to have covariant interior mutability...
nbdd0121 commentedon Jul 21, 2026
Well, I suppose if we have
CovariantUnsafeCellthenUnsafePinnedshould move to use that instead.