From f36058452d8c3f364b9b3e0690ae7df7ae661eaf Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Mon, 4 Aug 2025 09:34:07 +0000 Subject: [PATCH] Remove impl PinCoerceUnsized for Pin --- library/core/src/pin.rs | 3 -- library/coretests/tests/pin.rs | 3 -- .../arbitrary_self_types_stdlib_pointers.rs | 8 ---- .../pin-unsound-issue-85099-derefmut.rs | 5 ++- .../pin-unsound-issue-85099-derefmut.stderr | 39 +++++++++++++++++++ 5 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 tests/ui/typeck/pin-unsound-issue-85099-derefmut.stderr diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs index 14bf7ba90150e..2b972d8784ee6 100644 --- a/library/core/src/pin.rs +++ b/library/core/src/pin.rs @@ -1758,9 +1758,6 @@ unsafe impl<'a, T: ?Sized> PinCoerceUnsized for &'a T {} #[stable(feature = "pin", since = "1.33.0")] unsafe impl<'a, T: ?Sized> PinCoerceUnsized for &'a mut T {} -#[stable(feature = "pin", since = "1.33.0")] -unsafe impl PinCoerceUnsized for Pin {} - #[stable(feature = "pin", since = "1.33.0")] unsafe impl PinCoerceUnsized for *const T {} diff --git a/library/coretests/tests/pin.rs b/library/coretests/tests/pin.rs index b3fb06e710d44..88dc9bf4e4799 100644 --- a/library/coretests/tests/pin.rs +++ b/library/coretests/tests/pin.rs @@ -77,7 +77,4 @@ mod pin_coerce_unsized { pub fn pin_non_null(arg: Pin>) -> Pin> { arg } - pub fn nesting_pins(arg: Pin>) -> Pin> { - arg - } } diff --git a/tests/ui/self/arbitrary_self_types_stdlib_pointers.rs b/tests/ui/self/arbitrary_self_types_stdlib_pointers.rs index 4b8a21f764855..5381859fde149 100644 --- a/tests/ui/self/arbitrary_self_types_stdlib_pointers.rs +++ b/tests/ui/self/arbitrary_self_types_stdlib_pointers.rs @@ -13,7 +13,6 @@ trait Trait { fn by_arc(self: Arc) -> i64; fn by_pin_mut(self: Pin<&mut Self>) -> i64; fn by_pin_box(self: Pin>) -> i64; - fn by_pin_pin_pin_ref(self: Pin>>) -> i64; } impl Trait for i64 { @@ -29,9 +28,6 @@ impl Trait for i64 { fn by_pin_box(self: Pin>) -> i64 { *self } - fn by_pin_pin_pin_ref(self: Pin>>) -> i64 { - *self - } } fn main() { @@ -47,8 +43,4 @@ fn main() { let pin_box = Into::>>::into(Box::new(4i64)) as Pin>; assert_eq!(4, pin_box.by_pin_box()); - - let value = 5i64; - let pin_pin_pin_ref = Pin::new(Pin::new(Pin::new(&value))) as Pin>>; - assert_eq!(5, pin_pin_pin_ref.by_pin_pin_pin_ref()); } diff --git a/tests/ui/typeck/pin-unsound-issue-85099-derefmut.rs b/tests/ui/typeck/pin-unsound-issue-85099-derefmut.rs index f3ece563f5403..1e1bf99e39003 100644 --- a/tests/ui/typeck/pin-unsound-issue-85099-derefmut.rs +++ b/tests/ui/typeck/pin-unsound-issue-85099-derefmut.rs @@ -1,5 +1,4 @@ -//@ check-pass -//@ known-bug: #85099 +//@ check-fail // Should fail. Can coerce `Pin` into `Pin` where // `T: Deref` and `U: Deref`, using the @@ -59,6 +58,8 @@ pub fn unsound_pin>( let s: &SomeLocalStruct<'_, Fut> = &SomeLocalStruct(&cell); let p: Pin>> = Pin::new(Pin::new(s)); let mut p: Pin>> = p; + //~^ ERROR: the trait bound `Pin<&SomeLocalStruct<'_, Fut>>: PinCoerceUnsized` is not satisfied [E0277] + //~| ERROR: the trait bound `Pin<&dyn SomeTrait<'_, Fut>>: PinCoerceUnsized` is not satisfied [E0277] let r: Pin<&mut dyn SomeTrait<'_, Fut>> = p.as_mut(); let f: Pin<&mut Fut> = r.downcast(); callback(f); diff --git a/tests/ui/typeck/pin-unsound-issue-85099-derefmut.stderr b/tests/ui/typeck/pin-unsound-issue-85099-derefmut.stderr new file mode 100644 index 0000000000000..5d8ffa6451199 --- /dev/null +++ b/tests/ui/typeck/pin-unsound-issue-85099-derefmut.stderr @@ -0,0 +1,39 @@ +error[E0277]: the trait bound `Pin<&SomeLocalStruct<'_, Fut>>: PinCoerceUnsized` is not satisfied + --> $DIR/pin-unsound-issue-85099-derefmut.rs:60:52 + | +LL | let mut p: Pin>> = p; + | ^ the trait `PinCoerceUnsized` is not implemented for `Pin<&SomeLocalStruct<'_, Fut>>` + | + = help: the following other types implement trait `PinCoerceUnsized`: + &'a T + &'a mut T + *const T + *mut T + Arc + Box + Cell + NonNull + and 11 others + = note: required for the cast from `Pin>>` to `Pin>>` + +error[E0277]: the trait bound `Pin<&dyn SomeTrait<'_, Fut>>: PinCoerceUnsized` is not satisfied + --> $DIR/pin-unsound-issue-85099-derefmut.rs:60:52 + | +LL | let mut p: Pin>> = p; + | ^ the trait `PinCoerceUnsized` is not implemented for `Pin<&dyn SomeTrait<'_, Fut>>` + | + = help: the following other types implement trait `PinCoerceUnsized`: + &'a T + &'a mut T + *const T + *mut T + Arc + Box + Cell + NonNull + and 11 others + = note: required for the cast from `Pin>>` to `Pin>>` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`.