Skip to content

Commit f921d32

Browse files
committed
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<&mut dyn Send>`, but not being able to coerce to `Pin<&i32>`. However, I don't think it's possible to fix this. Fixes #145081
1 parent 27b076a commit f921d32

File tree

7 files changed

+1
-58
lines changed

7 files changed

+1
-58
lines changed

library/alloc/src/rc.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,9 +2341,6 @@ unsafe impl<T: ?Sized, A: Allocator> PinCoerceUnsized for Rc<T, A> {}
23412341
#[unstable(feature = "pin_coerce_unsized_trait", issue = "123430")]
23422342
unsafe impl<T: ?Sized, A: Allocator> PinCoerceUnsized for UniqueRc<T, A> {}
23432343

2344-
#[unstable(feature = "pin_coerce_unsized_trait", issue = "123430")]
2345-
unsafe impl<T: ?Sized, A: Allocator> PinCoerceUnsized for Weak<T, A> {}
2346-
23472344
#[unstable(feature = "deref_pure_trait", issue = "87121")]
23482345
unsafe impl<T: ?Sized, A: Allocator> DerefPure for Rc<T, A> {}
23492346

library/alloc/src/sync.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,9 +2330,6 @@ impl<T: ?Sized, A: Allocator> Deref for Arc<T, A> {
23302330
#[unstable(feature = "pin_coerce_unsized_trait", issue = "123430")]
23312331
unsafe impl<T: ?Sized, A: Allocator> PinCoerceUnsized for Arc<T, A> {}
23322332

2333-
#[unstable(feature = "pin_coerce_unsized_trait", issue = "123430")]
2334-
unsafe impl<T: ?Sized, A: Allocator> PinCoerceUnsized for Weak<T, A> {}
2335-
23362333
#[unstable(feature = "deref_pure_trait", issue = "87121")]
23372334
unsafe impl<T: ?Sized, A: Allocator> DerefPure for Arc<T, A> {}
23382335

library/core/src/cell.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,18 +2679,6 @@ fn assert_coerce_unsized(
26792679
let _: RefCell<&dyn Send> = d;
26802680
}
26812681

2682-
#[unstable(feature = "pin_coerce_unsized_trait", issue = "123430")]
2683-
unsafe impl<T: ?Sized> PinCoerceUnsized for UnsafeCell<T> {}
2684-
2685-
#[unstable(feature = "pin_coerce_unsized_trait", issue = "123430")]
2686-
unsafe impl<T: ?Sized> PinCoerceUnsized for SyncUnsafeCell<T> {}
2687-
2688-
#[unstable(feature = "pin_coerce_unsized_trait", issue = "123430")]
2689-
unsafe impl<T: ?Sized> PinCoerceUnsized for Cell<T> {}
2690-
2691-
#[unstable(feature = "pin_coerce_unsized_trait", issue = "123430")]
2692-
unsafe impl<T: ?Sized> PinCoerceUnsized for RefCell<T> {}
2693-
26942682
#[unstable(feature = "pin_coerce_unsized_trait", issue = "123430")]
26952683
unsafe impl<'b, T: ?Sized> PinCoerceUnsized for Ref<'b, T> {}
26962684

library/core/src/pin.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,7 @@ where
18441844
/// to. The concrete type of a slice is an array of the same element type and
18451845
/// the length specified in the metadata. The concrete type of a sized type
18461846
/// is the type itself.
1847-
pub unsafe trait PinCoerceUnsized {}
1847+
pub unsafe trait PinCoerceUnsized: Deref {}
18481848

18491849
#[stable(feature = "pin", since = "1.33.0")]
18501850
unsafe impl<'a, T: ?Sized> PinCoerceUnsized for &'a T {}
@@ -1855,12 +1855,6 @@ unsafe impl<'a, T: ?Sized> PinCoerceUnsized for &'a mut T {}
18551855
#[stable(feature = "pin", since = "1.33.0")]
18561856
unsafe impl<T: PinCoerceUnsized> PinCoerceUnsized for Pin<T> {}
18571857

1858-
#[stable(feature = "pin", since = "1.33.0")]
1859-
unsafe impl<T: ?Sized> PinCoerceUnsized for *const T {}
1860-
1861-
#[stable(feature = "pin", since = "1.33.0")]
1862-
unsafe impl<T: ?Sized> PinCoerceUnsized for *mut T {}
1863-
18641858
/// Constructs a <code>[Pin]<[&mut] T></code>, by pinning a `value: T` locally.
18651859
///
18661860
/// Unlike [`Box::pin`], this does not create a new heap allocation. As explained

library/core/src/ptr/non_null.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::marker::{Destruct, PointeeSized, Unsize};
44
use crate::mem::{MaybeUninit, SizedTypeProperties};
55
use crate::num::NonZero;
66
use crate::ops::{CoerceUnsized, DispatchFromDyn};
7-
use crate::pin::PinCoerceUnsized;
87
use crate::ptr::Unique;
98
use crate::slice::{self, SliceIndex};
109
use crate::ub_checks::assert_unsafe_precondition;
@@ -1664,9 +1663,6 @@ impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<NonNull<U>> for NonNull<T>
16641663
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
16651664
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
16661665

1667-
#[stable(feature = "pin", since = "1.33.0")]
1668-
unsafe impl<T: PointeeSized> PinCoerceUnsized for NonNull<T> {}
1669-
16701666
#[stable(feature = "nonnull", since = "1.25.0")]
16711667
impl<T: PointeeSized> fmt::Debug for NonNull<T> {
16721668
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

library/core/src/ptr/unique.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::clone::TrivialClone;
22
use crate::fmt;
33
use crate::marker::{PhantomData, PointeeSized, Unsize};
44
use crate::ops::{CoerceUnsized, DispatchFromDyn};
5-
use crate::pin::PinCoerceUnsized;
65
use crate::ptr::NonNull;
76

87
/// 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
176175
#[unstable(feature = "ptr_internals", issue = "none")]
177176
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
178177

179-
#[unstable(feature = "pin_coerce_unsized_trait", issue = "123430")]
180-
unsafe impl<T: PointeeSized> PinCoerceUnsized for Unique<T> {}
181-
182178
#[unstable(feature = "ptr_internals", issue = "none")]
183179
impl<T: PointeeSized> fmt::Debug for Unique<T> {
184180
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

library/coretests/tests/pin.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,38 +45,13 @@ mod pin_coerce_unsized {
4545
pub trait MyTrait {}
4646
impl MyTrait for String {}
4747

48-
// These Pins should continue to compile.
49-
// Do note that these instances of Pin types cannot be used
50-
// meaningfully because all methods require a Deref/DerefMut
51-
// bounds on the pointer type and Cell, RefCell and UnsafeCell
52-
// do not implement Deref/DerefMut.
53-
54-
pub fn cell(arg: Pin<Cell<Box<String>>>) -> Pin<Cell<Box<dyn MyTrait>>> {
55-
arg
56-
}
57-
pub fn ref_cell(arg: Pin<RefCell<Box<String>>>) -> Pin<RefCell<Box<dyn MyTrait>>> {
58-
arg
59-
}
60-
pub fn unsafe_cell(arg: Pin<UnsafeCell<Box<String>>>) -> Pin<UnsafeCell<Box<dyn MyTrait>>> {
61-
arg
62-
}
63-
6448
// These sensible Pin coercions are possible.
6549
pub fn pin_mut_ref(arg: Pin<&mut String>) -> Pin<&mut dyn MyTrait> {
6650
arg
6751
}
6852
pub fn pin_ref(arg: Pin<&String>) -> Pin<&dyn MyTrait> {
6953
arg
7054
}
71-
pub fn pin_ptr(arg: Pin<*const String>) -> Pin<*const dyn MyTrait> {
72-
arg
73-
}
74-
pub fn pin_ptr_mut(arg: Pin<*mut String>) -> Pin<*mut dyn MyTrait> {
75-
arg
76-
}
77-
pub fn pin_non_null(arg: Pin<NonNull<String>>) -> Pin<NonNull<dyn MyTrait>> {
78-
arg
79-
}
8055
pub fn nesting_pins(arg: Pin<Pin<&String>>) -> Pin<Pin<&dyn MyTrait>> {
8156
arg
8257
}

0 commit comments

Comments
 (0)