Rollup merge of #125048 - dingxiangfei2009:stable-deref, r=amanieu · patricklam/verify-rust-std@e20aa64
@@ -1715,10 +1715,56 @@ impl<Ptr: fmt::Pointer> fmt::Pointer for Pin<Ptr> {
17151715// for other reasons, though, so we just need to take care not to allow such
17161716// impls to land in std.
17171717#[stable(feature = "pin", since = "1.33.0")]
1718-impl<Ptr, U> CoerceUnsized<Pin<U>> for Pin<Ptr> where Ptr: CoerceUnsized<U> {}
1718+impl<Ptr, U> CoerceUnsized<Pin<U>> for Pin<Ptr>
1719+where
1720+Ptr: CoerceUnsized<U> + PinCoerceUnsized,
1721+U: PinCoerceUnsized,
1722+{
1723+}
1724+1725+#[stable(feature = "pin", since = "1.33.0")]
1726+impl<Ptr, U> DispatchFromDyn<Pin<U>> for Pin<Ptr>
1727+where
1728+Ptr: DispatchFromDyn<U> + PinCoerceUnsized,
1729+U: PinCoerceUnsized,
1730+{
1731+}
1732+1733+#[unstable(feature = "pin_coerce_unsized_trait", issue = "123430")]
1734+/// Trait that indicates that this is a pointer or a wrapper for one, where
1735+/// unsizing can be performed on the pointee when it is pinned.
1736+///
1737+/// # Safety
1738+///
1739+/// If this type implements `Deref`, then the concrete type returned by `deref`
1740+/// and `deref_mut` must not change without a modification. The following
1741+/// operations are not considered modifications:
1742+///
1743+/// * Moving the pointer.
1744+/// * Performing unsizing coercions on the pointer.
1745+/// * Performing dynamic dispatch with the pointer.
1746+/// * Calling `deref` or `deref_mut` on the pointer.
1747+///
1748+/// The concrete type of a trait object is the type that the vtable corresponds
1749+/// to. The concrete type of a slice is an array of the same element type and
1750+/// the length specified in the metadata. The concrete type of a sized type
1751+/// is the type itself.
1752+pub unsafe trait PinCoerceUnsized {}
1753+1754+#[stable(feature = "pin", since = "1.33.0")]
1755+unsafe impl<'a, T: ?Sized> PinCoerceUnsized for &'a T {}
1756+1757+#[stable(feature = "pin", since = "1.33.0")]
1758+unsafe impl<'a, T: ?Sized> PinCoerceUnsized for &'a mut T {}
1759+1760+#[stable(feature = "pin", since = "1.33.0")]
1761+unsafe impl<T: PinCoerceUnsized> PinCoerceUnsized for Pin<T> {}
1762+1763+#[stable(feature = "pin", since = "1.33.0")]
1764+unsafe impl<T: ?Sized> PinCoerceUnsized for *const T {}
1719176517201766#[stable(feature = "pin", since = "1.33.0")]
1721-impl<Ptr, U> DispatchFromDyn<Pin<U>> for Pin<Ptr> where Ptr: DispatchFromDyn<U> {}
1767+unsafe impl<T: ?Sized> PinCoerceUnsized for *mut T {}
1722176817231769/// Constructs a <code>[Pin]<[&mut] T></code>, by pinning a `value: T` locally.
17241770///