Interaction between `Pin` soundness and arbitrary self types
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
#![feature(arbitrary_self_types)]
use std::marker::PhantomPinned;
use std::ops::Receiver;
use std::pin::Pin;
trait MyTrait {
fn hello(self: Pin<&mut Foo<Self>>) -> Pin<&mut Foo<u32>>;
}
impl MyTrait for u32 {
fn hello(self: Pin<&mut Foo<Self>>) -> Pin<&mut Foo<u32>> {
self
}
}
struct Foo<T: ?Sized> {
_pin: PhantomPinned,
val: T,
}
impl<T: ?Sized> Receiver for Foo<T> {
type Target = T;
}
impl Unpin for Foo<dyn MyTrait> {}
fn pin_it(r: &mut Foo<u32>) -> Pin<&mut Foo<u32>> {
Pin::<&mut Foo<dyn MyTrait>>::new(r).hello()
}
In the above piece of code, I'm able to convert a &mut Foo<u32> into a Pin<&mut Foo<u32>> even though the type Foo<u32> is !Unpin.
I'm not sure if you can concretely abuse this to trigger UB right now, but it seems bad.
Related test case:
https://github.com/rust-lang/rust/blob/b5e038d7158c1af55a646027fdacf5ecd7c783c7/tests/ui/coercion/pin-dyn-dispatch-sound.rs#L1-L19
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducer in the issue and the related tests in tests/ui/coercion/pin-dyn-dispatch-sound.rs and its .stderr file. Run that UI test, then investigate the interaction between arbitrary self types, Pin, Receiver, and Unpin; done means establishing whether the conversion is unsound and documenting or implementing the required compiler behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100