-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implement Unpin for Box, Rc, and Arc #53874
Conversation
r? @KodrAus (rust_highfive has picked a reviewer for you, use r? to override) |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
src/liballoc/rc.rs
Outdated
@@ -1830,3 +1830,6 @@ impl<T: ?Sized> AsRef<T> for Rc<T> { | |||
&**self | |||
} | |||
} | |||
|
|||
#[unstable(feature = "pin", issue = "49150")] | |||
impl<T: ?Sized> Unpin for Box<T> { } |
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.
This looks like a copy-paste woops, it should be Rc
, right? XD
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.
yep whoops!
src/liballoc/boxed.rs
Outdated
@@ -749,6 +749,9 @@ impl<T: ?Sized> AsMut<T> for Box<T> { | |||
} | |||
} | |||
|
|||
#[unstable(feature = "pin", issue = "49150")] | |||
impl<T: ?Sized> Unpin for Box<T> { } |
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 tried looking through the issue, and it wasn't immediately clear: why is a Box unpin? After using a pin, we could move out of the box afterwards, right?
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.
Best summary is this comment under "adding Unpin
implementations" TL;DR is you're right, but putting the box in the pin doesn't pin the stuff in the heap, only the box's stack representation (i.e. the actual pointer)
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.
Both interpretations of Box are valid, but this one is the most useful and consistent with other types (in that pin-projection is related to whether or not the data is stored out-of-line). If a Box is pinned, then there isn't a way to move the underlying data unless we choose to make it Unpin
, so the other choice is fine as well.
LGTM, but I feel those arguments about r=me with that comment added. |
@bors r=RalfJung |
📌 Commit c82af09 has been approved by |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
src/liballoc/boxed.rs
Outdated
* standard library pointer types support projecting through a pin | ||
* (Box<T> is the only pointer type in std for which this would be | ||
* safe.) | ||
* - It is in practive very useful to have Box<T> be unconditionally |
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.
Nit: s/practive/practice/
src/liballoc/boxed.rs
Outdated
@@ -749,6 +749,31 @@ impl<T: ?Sized> AsMut<T> for Box<T> { | |||
} | |||
} | |||
|
|||
/* Nota bene | |||
* | |||
* We could have chosen not to add this impl, and instead have written a |
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.
Trailing whitespace fails tidy
@bors r- Tidy failed. |
@bors r=RalfJung |
📌 Commit 972cd8b has been approved by |
@bors rollup |
Implement Unpin for Box, Rc, and Arc Per the discussion in rust-lang#49150, these should implement `Unpin` even if what they point to does not.
Rollup of 17 pull requests Successful merges: - #53299 (Updated core/macros.rs to note it works in a no_std environment.) - #53376 (Cross reference io::copy and fs::copy in docs.) - #53455 (Individual docs for {from,to}_*_bytes) - #53550 (librustc_lint: In recursion warning, change 'recurring' to 'recursing') - #53860 (Migrate (some) of run-pass/ to ui) - #53874 (Implement Unpin for Box, Rc, and Arc) - #53895 (tidy: Cleanups and clippy warning fixes) - #53946 (Clarify `ManuallyDrop` docs) - #53948 (Minimized clippy test from when NLL disabled two-phase borrows) - #53959 (Add .git extension to submodule paths missing it) - #53966 (A few cleanups and minor improvements to mir/dataflow) - #53967 (propagate build.python into cmake) - #53979 (Remove `#[repr(transparent)]` from atomics) - #53991 (Add unchecked_shl/shr check for intrinsics to fix miri's test suit) - #53992 (migrate run-pass/borrowck to ui/run-pass) - #53994 (migrate run-pass/*/ to ui/run-pass) - #54023 (update clippy submodule)
Per the discussion in #49150, these should implement
Unpin
even if what they point to does not.