File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -749,6 +749,28 @@ impl<T: ?Sized> AsMut<T> for Box<T> {
749
749
}
750
750
}
751
751
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
+ */
752
774
#[ unstable( feature = "pin" , issue = "49150" ) ]
753
775
impl < T : ?Sized > Unpin for Box < T > { }
754
776
You can’t perform that action at this time.
0 commit comments