forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Require #[pin_v2] for direct &pin borrows of ADTs #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
frank-king
merged 1 commit into
frank-king:feature/pin-borrowck
from
P8L1:enforce-pin-v2-for-direct-pin-borrows
Apr 29, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
|
|
||
| use std::pin::Pin; | ||
|
|
||
| #[pin_v2] | ||
| struct Foo; | ||
|
|
||
| fn foo_pin_mut(_: Pin<&mut Foo>) {} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #![feature(pin_ergonomics)] | ||
| #![allow(incomplete_features)] | ||
| //@ normalize-stderr: "\n\n\z" -> "\n" | ||
|
|
||
| struct NotPinV2; | ||
|
|
||
| fn direct_pin_mut(mut value: NotPinV2) { | ||
| let _ = &pin mut value; | ||
| //~^ ERROR cannot directly pin an ADT that is not `#[pin_v2]` | ||
| } | ||
|
|
||
| fn direct_pin_const(value: NotPinV2) { | ||
| let _ = &pin const value; | ||
| //~^ ERROR cannot directly pin an ADT that is not `#[pin_v2]` | ||
| } | ||
|
|
||
| fn main() {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having read the failed CI cases thoroughly, instead of directly reporting
cannot directly pin an ADT that is not `#[pin_v2]`, I now prefer checking ifADT: Unpinfirst and report this error only for ADTs that are!Unpin.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened a follow-up PR for the
Unpingate change here: #4It keeps the diagnostic limited to explicit
&pinborrows, but only emits it for non-#[pin_v2]ADTs that are known/proven to be!Unpin.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tested this behavior? In case that pinned borrow may be inconsistent with the pinned patterns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think allowing
&pinborrows forGenericAdt<T>is unsound if it is unknown to beUnpinor!Unpin.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed.
Refer to: #4
Direct
&pinno longer relies only on the outer type satisfyingUnpin. Generic ADTs are now rejected unless they are#[pin_v2], and generic/unknown field targets likeTare rejected instead of being accepted conservatively.This prevents a manual
impl<T> Unpin for Wrapper<T>from bypassing structural pin-safety restrictions and keeps the direct&pinborrow path aligned with pinned-pattern projection safety.I added regression coverage for the generic field projection case, the unconditional manual
impl<T> Unpinwrapper, and the genericDropwrapper. I also updated the diagnostic wording from “ADT” to “type” because one rejected case can target a generic parameter rather than an ADT directly.Tested with the focused pin-ergonomics suite,
tidy,fmt --check, andgit diff --check. I did not run the fulltests/uisuite locally because it is too broad/expensive, but the focused pin-ergonomics suite passes.