-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example of moving Pin is confusing #157
Comments
I agree with you, the error is just because it is not |
You are correct. No move occurs here. The error is caused by trying to get a mutable/exclusive pointer to If you look at the implementation of swap_simple in the standard library (used for swapping smaller objects), you'll actually see in the comments that this method, while safe to use, assumes "exclusive references are always valid to read/write", and the latter is not the case with Pinned // SAFETY: exclusive references are always valid to read/write,
// including being aligned, and nothing here panics so it's drop-safe.
unsafe {
let a = ptr::read(x);
let b = ptr::read(y);
ptr::write(x, b);
ptr::write(y, a);
}
} So, while the error occurs when you try to get a mutable/exclusive reference, the reason behind forbidding you to obtain that for |
It makes sense to me |
In the Pin(4th) chapter, there is an example showing that we cannot move data if we pinned it, and use
std::mem::swap
to prove it.But the compilation error is about
Pin::get_mut
:It's because the signature is
while our
Test
isn'tUnpin
, I think it has no connection withstd::mem::swap
, and no move occurs here, right?The text was updated successfully, but these errors were encountered: