mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Make PinCoerceUnsized require Deref
Also, delete impls on non-Deref types. Pin doesn't do anything useful for non-Deref types, so PinCoerceUnsized on such types makes no sense. This is a breaking change, since stable code can observe the deleted `PinCoerceUnsized` impls by uselessly coercing between such types inside a `Pin`. There is still some strange behavior, such as `Pin<&mut i32>` being able to coerce to `Pin<&dyn Send>`, but not being able to coerce to `Pin<&i32>`. However, I don't think it's possible to fix this. Fixes https://github.com/rust-lang/rust/issues/145081
This commit is contained in:
committed by
Tim (Theemathas) Chirananthavat
parent
8a703520e8
commit
1e4c1d6f75
@@ -2424,9 +2424,6 @@ unsafe impl<T: ?Sized, A: Allocator> PinCoerceUnsized for Rc<T, A> {}
|
||||
#[unstable(feature = "pin_coerce_unsized_trait", issue = "150112")]
|
||||
unsafe impl<T: ?Sized, A: Allocator> PinCoerceUnsized for UniqueRc<T, A> {}
|
||||
|
||||
#[unstable(feature = "pin_coerce_unsized_trait", issue = "150112")]
|
||||
unsafe impl<T: ?Sized, A: Allocator> PinCoerceUnsized for Weak<T, A> {}
|
||||
|
||||
#[unstable(feature = "deref_pure_trait", issue = "87121")]
|
||||
unsafe impl<T: ?Sized, A: Allocator> DerefPure for Rc<T, A> {}
|
||||
|
||||
|
||||
@@ -2426,9 +2426,6 @@ fn deref(&self) -> &T {
|
||||
#[unstable(feature = "pin_coerce_unsized_trait", issue = "150112")]
|
||||
unsafe impl<T: ?Sized, A: Allocator> PinCoerceUnsized for Arc<T, A> {}
|
||||
|
||||
#[unstable(feature = "pin_coerce_unsized_trait", issue = "150112")]
|
||||
unsafe impl<T: ?Sized, A: Allocator> PinCoerceUnsized for Weak<T, A> {}
|
||||
|
||||
#[unstable(feature = "deref_pure_trait", issue = "87121")]
|
||||
unsafe impl<T: ?Sized, A: Allocator> DerefPure for Arc<T, A> {}
|
||||
|
||||
|
||||
@@ -2718,18 +2718,6 @@ fn assert_coerce_unsized(
|
||||
let _: RefCell<&dyn Send> = d;
|
||||
}
|
||||
|
||||
#[unstable(feature = "pin_coerce_unsized_trait", issue = "150112")]
|
||||
unsafe impl<T: ?Sized> PinCoerceUnsized for UnsafeCell<T> {}
|
||||
|
||||
#[unstable(feature = "pin_coerce_unsized_trait", issue = "150112")]
|
||||
unsafe impl<T: ?Sized> PinCoerceUnsized for SyncUnsafeCell<T> {}
|
||||
|
||||
#[unstable(feature = "pin_coerce_unsized_trait", issue = "150112")]
|
||||
unsafe impl<T: ?Sized> PinCoerceUnsized for Cell<T> {}
|
||||
|
||||
#[unstable(feature = "pin_coerce_unsized_trait", issue = "150112")]
|
||||
unsafe impl<T: ?Sized> PinCoerceUnsized for RefCell<T> {}
|
||||
|
||||
#[unstable(feature = "pin_coerce_unsized_trait", issue = "150112")]
|
||||
unsafe impl<'b, T: ?Sized> PinCoerceUnsized for Ref<'b, T> {}
|
||||
|
||||
|
||||
@@ -1842,7 +1842,7 @@ impl<Ptr, U> DispatchFromDyn<Pin<U>> for Pin<Ptr>
|
||||
/// to. The concrete type of a slice is an array of the same element type and
|
||||
/// the length specified in the metadata. The concrete type of a sized type
|
||||
/// is the type itself.
|
||||
pub unsafe trait PinCoerceUnsized {}
|
||||
pub unsafe trait PinCoerceUnsized: Deref {}
|
||||
|
||||
#[stable(feature = "pin", since = "1.33.0")]
|
||||
unsafe impl<'a, T: ?Sized> PinCoerceUnsized for &'a T {}
|
||||
@@ -1853,12 +1853,6 @@ unsafe impl<'a, T: ?Sized> PinCoerceUnsized for &'a mut T {}
|
||||
#[stable(feature = "pin", since = "1.33.0")]
|
||||
unsafe impl<T: PinCoerceUnsized> PinCoerceUnsized for Pin<T> {}
|
||||
|
||||
#[stable(feature = "pin", since = "1.33.0")]
|
||||
unsafe impl<T: ?Sized> PinCoerceUnsized for *const T {}
|
||||
|
||||
#[stable(feature = "pin", since = "1.33.0")]
|
||||
unsafe impl<T: ?Sized> PinCoerceUnsized for *mut T {}
|
||||
|
||||
/// Constructs a <code>[Pin]<[&mut] T></code>, by pinning a `value: T` locally.
|
||||
///
|
||||
/// Unlike [`Box::pin`], this does not create a new heap allocation. As explained
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
use crate::mem::{MaybeUninit, SizedTypeProperties, transmute};
|
||||
use crate::num::NonZero;
|
||||
use crate::ops::{CoerceUnsized, DispatchFromDyn};
|
||||
use crate::pin::PinCoerceUnsized;
|
||||
use crate::ptr::Unique;
|
||||
use crate::slice::{self, SliceIndex};
|
||||
use crate::ub_checks::assert_unsafe_precondition;
|
||||
@@ -1692,9 +1691,6 @@ impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<NonNull<U>> for NonNull<T>
|
||||
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
|
||||
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
|
||||
|
||||
#[stable(feature = "pin", since = "1.33.0")]
|
||||
unsafe impl<T: PointeeSized> PinCoerceUnsized for NonNull<T> {}
|
||||
|
||||
#[stable(feature = "nonnull", since = "1.25.0")]
|
||||
impl<T: PointeeSized> fmt::Debug for NonNull<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
use crate::fmt;
|
||||
use crate::marker::{PhantomData, PointeeSized, Unsize};
|
||||
use crate::ops::{CoerceUnsized, DispatchFromDyn};
|
||||
use crate::pin::PinCoerceUnsized;
|
||||
use crate::ptr::NonNull;
|
||||
|
||||
/// A wrapper around a raw non-null `*mut T` that indicates that the possessor
|
||||
@@ -176,9 +175,6 @@ impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<Unique<U>> for Unique<T> wh
|
||||
#[unstable(feature = "ptr_internals", issue = "none")]
|
||||
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
|
||||
|
||||
#[unstable(feature = "pin_coerce_unsized_trait", issue = "150112")]
|
||||
unsafe impl<T: PointeeSized> PinCoerceUnsized for Unique<T> {}
|
||||
|
||||
#[unstable(feature = "ptr_internals", issue = "none")]
|
||||
impl<T: PointeeSized> fmt::Debug for Unique<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
|
||||
@@ -45,22 +45,6 @@ mod pin_coerce_unsized {
|
||||
pub trait MyTrait {}
|
||||
impl MyTrait for String {}
|
||||
|
||||
// These Pins should continue to compile.
|
||||
// Do note that these instances of Pin types cannot be used
|
||||
// meaningfully because all methods require a Deref/DerefMut
|
||||
// bounds on the pointer type and Cell, RefCell and UnsafeCell
|
||||
// do not implement Deref/DerefMut.
|
||||
|
||||
pub fn cell(arg: Pin<Cell<Box<String>>>) -> Pin<Cell<Box<dyn MyTrait>>> {
|
||||
arg
|
||||
}
|
||||
pub fn ref_cell(arg: Pin<RefCell<Box<String>>>) -> Pin<RefCell<Box<dyn MyTrait>>> {
|
||||
arg
|
||||
}
|
||||
pub fn unsafe_cell(arg: Pin<UnsafeCell<Box<String>>>) -> Pin<UnsafeCell<Box<dyn MyTrait>>> {
|
||||
arg
|
||||
}
|
||||
|
||||
// These sensible Pin coercions are possible.
|
||||
pub fn pin_mut_ref(arg: Pin<&mut String>) -> Pin<&mut dyn MyTrait> {
|
||||
arg
|
||||
@@ -68,15 +52,6 @@ pub fn pin_mut_ref(arg: Pin<&mut String>) -> Pin<&mut dyn MyTrait> {
|
||||
pub fn pin_ref(arg: Pin<&String>) -> Pin<&dyn MyTrait> {
|
||||
arg
|
||||
}
|
||||
pub fn pin_ptr(arg: Pin<*const String>) -> Pin<*const dyn MyTrait> {
|
||||
arg
|
||||
}
|
||||
pub fn pin_ptr_mut(arg: Pin<*mut String>) -> Pin<*mut dyn MyTrait> {
|
||||
arg
|
||||
}
|
||||
pub fn pin_non_null(arg: Pin<NonNull<String>>) -> Pin<NonNull<dyn MyTrait>> {
|
||||
arg
|
||||
}
|
||||
pub fn nesting_pins(arg: Pin<Pin<&String>>) -> Pin<Pin<&dyn MyTrait>> {
|
||||
arg
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
use crate::convert::TryInto;
|
||||
use crate::mem::{self, ManuallyDrop, MaybeUninit};
|
||||
use crate::ops::{CoerceUnsized, Deref, DerefMut, Index, IndexMut};
|
||||
use crate::pin::PinCoerceUnsized;
|
||||
use crate::ptr::{self, NonNull};
|
||||
use crate::slice::SliceIndex;
|
||||
use crate::{cmp, intrinsics, slice};
|
||||
@@ -773,9 +772,6 @@ fn drop(&mut self) {
|
||||
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||
impl<T: CoerceUnsized<U>, U> CoerceUnsized<UserRef<U>> for UserRef<T> {}
|
||||
|
||||
#[unstable(feature = "pin_coerce_unsized_trait", issue = "150112")]
|
||||
unsafe impl<T: ?Sized> PinCoerceUnsized for UserRef<T> {}
|
||||
|
||||
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||
impl<T, I> Index<I> for UserRef<[T]>
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user