Skip to content

Commit c82af09

Browse files
author
Without Boats
committed
Add comment.
1 parent 9ff29d6 commit c82af09

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/liballoc/boxed.rs

+22
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,28 @@ impl<T: ?Sized> AsMut<T> for Box<T> {
749749
}
750750
}
751751

752+
/* Nota bene
753+
*
754+
* We could have chosen not to add this impl, and instead have written a
755+
* function of Pin<Box<T>> to Pin<T>. Such a function would not be sound,
756+
* because Box<T> implements Unpin even when T does not, as a result of
757+
* this impl.
758+
*
759+
* We chose this API instead of the alternative for a few reasons:
760+
* - Logically, it is helpful to understand pinning in regard to the
761+
* memory region being pointed to. For this reason none of the
762+
* standard library pointer types support projecting through a pin
763+
* (Box<T> is the only pointer type in std for which this would be
764+
* safe.)
765+
* - It is in practive very useful to have Box<T> be unconditionally
766+
* Unpin because of trait objects, for which the structural auto
767+
* trait functionality does not apply (e.g. Box<dyn Foo> would
768+
* otherwise not be Unpin).
769+
*
770+
* Another type with the same semantics as Box but only a conditional
771+
* implementation of `Unpin` (where `T: Unpin`) would be valid/safe, and
772+
* could have a method to project a Pin<T> from it.
773+
*/
752774
#[unstable(feature = "pin", issue = "49150")]
753775
impl<T: ?Sized> Unpin for Box<T> { }
754776

0 commit comments

Comments
 (0)