-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add a stack-pin!
-ning macro to core::pin
.
#93176
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
bors
merged 8 commits into
rust-lang:master
from
danielhenrymantilla:stack-pinning-macro
Feb 15, 2022
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ee9cd7b
Add a stack-`pin!`-ning macro to the `pin` module.
danielhenrymantilla 42d69e2
Write {ui,} tests for `pin_macro` and `pin!`
danielhenrymantilla 5360469
Update `macro:print` typed-query rustdoc test to include `pin!` results
danielhenrymantilla 54e443d
Improve documentation.
danielhenrymantilla 6df63cc
Replace `def_site`-&-privacy implementation with a stability-based one.
danielhenrymantilla c93968a
Mark `unsafe_pin_internals` as `incomplete`.
danielhenrymantilla 002f627
Add a comment to justify why the `pointer` field is `pub`.
danielhenrymantilla bf2a9dc
Update unsafe_pin_internals unstable version.
m-ou-se 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// edition:2021 | ||
use core::{ | ||
marker::PhantomPinned, | ||
mem::{drop as stuff, transmute}, | ||
pin::{pin, Pin}, | ||
}; | ||
|
||
#[test] | ||
fn basic() { | ||
let it: Pin<&mut PhantomPinned> = pin!(PhantomPinned); | ||
stuff(it); | ||
} | ||
|
||
#[test] | ||
fn extension_works_through_block() { | ||
let it: Pin<&mut PhantomPinned> = { pin!(PhantomPinned) }; | ||
stuff(it); | ||
} | ||
|
||
#[test] | ||
fn extension_works_through_unsafe_block() { | ||
// "retro-type-inference" works as well. | ||
let it: Pin<&mut PhantomPinned> = unsafe { pin!(transmute(())) }; | ||
stuff(it); | ||
} | ||
|
||
#[test] | ||
fn unsize_coercion() { | ||
let slice: Pin<&mut [PhantomPinned]> = pin!([PhantomPinned; 2]); | ||
stuff(slice); | ||
let dyn_obj: Pin<&mut dyn Send> = pin!([PhantomPinned; 2]); | ||
stuff(dyn_obj); | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/test/ui/feature-gates/feature-gate-unsafe_pin_internals.rs
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 @@ | ||
// edition:2018 | ||
#![forbid(incomplete_features, unsafe_code)] | ||
#![feature(unsafe_pin_internals)] | ||
//~^ ERROR the feature `unsafe_pin_internals` is incomplete and may not be safe to use | ||
|
||
use core::{marker::PhantomPinned, pin::Pin}; | ||
|
||
/// The `unsafe_pin_internals` is indeed unsound. | ||
fn non_unsafe_pin_new_unchecked<T>(pointer: &mut T) -> Pin<&mut T> { | ||
Pin { pointer } | ||
} | ||
|
||
fn main() { | ||
let mut self_referential = PhantomPinned; | ||
let _: Pin<&mut PhantomPinned> = non_unsafe_pin_new_unchecked(&mut self_referential); | ||
core::mem::forget(self_referential); // move and disable drop glue! | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/feature-gates/feature-gate-unsafe_pin_internals.stderr
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,14 @@ | ||
error: the feature `unsafe_pin_internals` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/feature-gate-unsafe_pin_internals.rs:3:12 | ||
| | ||
LL | #![feature(unsafe_pin_internals)] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/feature-gate-unsafe_pin_internals.rs:2:11 | ||
| | ||
LL | #![forbid(incomplete_features, unsafe_code)] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
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,13 @@ | ||
// edition:2018 | ||
#![feature(pin_macro)] | ||
|
||
use core::{ | ||
marker::PhantomPinned, | ||
mem, | ||
pin::{pin, Pin}, | ||
}; | ||
|
||
fn main() { | ||
let mut phantom_pinned = pin!(PhantomPinned); | ||
mem::take(phantom_pinned.pointer); //~ ERROR use of unstable library feature 'unsafe_pin_internals' | ||
} |
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,11 @@ | ||
error[E0658]: use of unstable library feature 'unsafe_pin_internals' | ||
--> $DIR/cant_access_internals.rs:12:15 | ||
| | ||
LL | mem::take(phantom_pinned.pointer); | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: add `#![feature(unsafe_pin_internals)]` to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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.
Uh oh!
There was an error while loading. Please reload this page.