-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Implement Unpin for Box, Rc, and Arc #53874
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
* function of Pin<Box<T>> to Pin<T>. Such a function would not be sound, | ||
* because Box<T> implements Unpin even when T does not, as a result of | ||
* this impl. | ||
* | ||
* We chose this API instead of the alternative for a few reasons: | ||
* - Logically, it is helpful to understand pinning in regard to the | ||
* memory region being pointed to. For this reason none of the | ||
* 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 commentThe reason will be displayed to describe this comment to others. Learn more. Nit: s/practive/practice/ |
||
* Unpin because of trait objects, for which the structural auto | ||
* trait functionality does not apply (e.g. Box<dyn Foo> would | ||
* otherwise not be Unpin). | ||
* | ||
* Another type with the same semantics as Box but only a conditional | ||
* implementation of `Unpin` (where `T: Unpin`) would be valid/safe, and | ||
* could have a method to project a Pin<T> from it. | ||
*/ | ||
#[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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Best summary is this comment under "adding There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
#[unstable(feature = "generator_trait", issue = "43122")] | ||
impl<T> Generator for Box<T> | ||
where T: Generator + ?Sized | ||
|
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