Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Implementations of DerefMove for Pin<_> types are unsound #34

Closed
SkiFire13 opened this issue Oct 5, 2022 · 1 comment
Closed

Implementations of DerefMove for Pin<_> types are unsound #34

SkiFire13 opened this issue Oct 5, 2022 · 1 comment

Comments

@SkiFire13
Copy link

DerefMove allows to get a MoveRef from self, and that's not pinned anymore. If self is a Pin type then this is unsound

use std::marker::PhantomPinned;
use std::pin::Pin;

use moveit::move_ref::DerefMove;
use moveit::slot;

struct Unmovable {
    _marker: PhantomPinned,
}

impl Unmovable {
    fn assert_pinned(self: Pin<&mut Self>) {
        println!("Pinned")
    }
    fn assert_unpinned(&mut self) {
        println!("Uninned")
    }
}

fn main() {
    // This also works for creating `unmovable`:
    // 
    // moveit::moveit!(let mut unmovable = moveit::new::of(Unmovable {
    //     _marker: PhantomPinned,
    // }));
    let mut unmovable = Box::pin(Unmovable {
        _marker: PhantomPinned,
    });
    unmovable.as_mut().assert_pinned();

    slot!(
        #[dropping]
        drop_slot: _
    );
    unmovable.deref_move(drop_slot).assert_unpinned();
}
@SkiFire13
Copy link
Author

Fixed by #38

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant