@@ -1717,10 +1717,50 @@ impl<Ptr: fmt::Pointer> fmt::Pointer for Pin<Ptr> {
1717
1717
// for other reasons, though, so we just need to take care not to allow such
1718
1718
// impls to land in std.
1719
1719
#[ stable( feature = "pin" , since = "1.33.0" ) ]
1720
- impl < Ptr , U > CoerceUnsized < Pin < U > > for Pin < Ptr > where Ptr : CoerceUnsized < U > { }
1720
+ impl < Ptr , U > CoerceUnsized < Pin < U > > for Pin < Ptr >
1721
+ where
1722
+ Ptr : CoerceUnsized < U > + PinCoerceUnsized ,
1723
+ U : PinCoerceUnsized ,
1724
+ {
1725
+ }
1726
+
1727
+ #[ stable( feature = "pin" , since = "1.33.0" ) ]
1728
+ impl < Ptr , U > DispatchFromDyn < Pin < U > > for Pin < Ptr >
1729
+ where
1730
+ Ptr : DispatchFromDyn < U > + PinCoerceUnsized ,
1731
+ U : PinCoerceUnsized ,
1732
+ {
1733
+ }
1734
+
1735
+ #[ unstable( feature = "pin_coerce_unsized_trait" , issue = "123430" ) ]
1736
+ /// # Safety
1737
+ ///
1738
+ /// Implementing this unsafe traits requires the guarantee that any two calls
1739
+ /// to `Deref::deref` must return the same value at the same address, **even after moves
1740
+ /// or unsize-coercions of `self`**, with exceptions of mutations to `self`.
1741
+ ///
1742
+ /// Here, "same value" means that if `deref` returns a trait object, then the actual
1743
+ /// concrete type behind that trait object must not change.
1744
+ /// Additionally, when you unsize- coerce from `Self` to `Unsized`,
1745
+ /// then if you call `deref` on `Unsized` which returns a trait object reference,
1746
+ /// the underlying type of that trait object must be `<Self as Deref>::Target`.
1747
+ ///
1748
+ /// Analogous requirements apply to other unsized types. E.g., if `deref` returns
1749
+ /// `[T]`, then the length must not change. In other words, the underlying type
1750
+ /// must not change from `[T; N]` to `[T; M]` with an `N` different from `M`.
1751
+ ///
1752
+ /// If this type alos implements `DerefMut`, then the same guarantee must be upheld by
1753
+ /// calls to `deref_mut`.
1754
+ pub unsafe trait PinCoerceUnsized : Deref { }
1755
+
1756
+ #[ stable( feature = "pin" , since = "1.33.0" ) ]
1757
+ unsafe impl < ' a , T : ?Sized > PinCoerceUnsized for & ' a T { }
1758
+
1759
+ #[ stable( feature = "pin" , since = "1.33.0" ) ]
1760
+ unsafe impl < ' a , T : ?Sized > PinCoerceUnsized for & ' a mut T { }
1721
1761
1722
1762
#[ stable( feature = "pin" , since = "1.33.0" ) ]
1723
- impl < Ptr , U > DispatchFromDyn < Pin < U > > for Pin < Ptr > where Ptr : DispatchFromDyn < U > { }
1763
+ unsafe impl < T : PinCoerceUnsized > PinCoerceUnsized for Pin < T > { }
1724
1764
1725
1765
/// Constructs a <code>[Pin]<[&mut] T></code>, by pinning a `value: T` locally.
1726
1766
///
0 commit comments