-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Add missing mut to pin.rs docs #150705
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
Add missing mut to pin.rs docs #150705
Conversation
|
Punting on pin, |
|
Sure, though this isn't intended to compile anyway... |
Only because Also, I figured the argument to This compiles: use std::cell::RefCell;
use std::pin::Pin;
trait RefCellPinExt<'a, T> {
fn get_pin_mut(self) -> Pin<&'a mut T>;
}
impl<'a, T> RefCellPinExt<'a, T> for Pin<&'a mut RefCell<T>> {
fn get_pin_mut(self) -> Pin<&'a mut T> {
// SAFETY: That's actually unsafe. Don't do this in real code!
unsafe { self.map_unchecked_mut(|rc| rc.get_mut()) }
}
}
fn exploit_ref_cell<T>(mut rc: Pin<&mut RefCell<T>>) {
// Here we get pinned access to the `T`.
let _: Pin<&mut T> = rc.as_mut().get_pin_mut();
// And here we have `&mut T` to the same data.
let shared: &RefCell<T> = rc.into_ref().get_ref();
let mut borrow = shared.borrow_mut();
let content = &mut *borrow;
}Maybe we better replace it with this version? It's longer, but the compiler can check that it compiles. It's incorrect and unsafe, but having it compile makes sure the example is not bogus. |
|
|
|
Updated to code that compiles, LMK WDYT |
This comment has been minimized.
This comment has been minimized.
|
@joboet ping |
I don't think that's a good idea. The example not compiling makes it even clearer that this is unsound. Could you please revert to the previous version?
😄. Sorry, I filter my review queue by |
|
@rustbot ready |
|
Thanks! Just one thing before I approve this again: Could you squash the commits into one, please? |
|
Not via github, I'm afraid. Can you use squash merge? Or is it an absolute requirement for me to clone the repo? |
Per my understanding, needed for mut access next line.
|
We use a custom merge bot that isn't able to do squash merges unfortunately. I've performed the squash for you. |
|
@rustbot ready |
|
@bors r+ rollup |
…r=joboet Add missing mut to pin.rs docs Per my understanding, needed for mut access next line.
Rollup of 6 pull requests Successful merges: - #151611 (Improve is_ascii performance on x86_64 with explicit SSE2 intrinsics) - #150705 (Add missing mut to pin.rs docs) - #151294 (compiletest: add implied `needs-target-std` for `codegen` mode tests unless annotated with `#![no_std]`/`#![no_core]`) - #151589 (Add a `documentation` remapping path scope for rustdoc usage) - #151639 (Fix broken WASIp1 reference link) - #151645 (Update `sysinfo` version to `0.38.0`)
Rollup merge of #150705 - justanotheranonymoususer:patch-1, r=joboet Add missing mut to pin.rs docs Per my understanding, needed for mut access next line.
Rollup of 6 pull requests Successful merges: - rust-lang/rust#151611 (Improve is_ascii performance on x86_64 with explicit SSE2 intrinsics) - rust-lang/rust#150705 (Add missing mut to pin.rs docs) - rust-lang/rust#151294 (compiletest: add implied `needs-target-std` for `codegen` mode tests unless annotated with `#![no_std]`/`#![no_core]`) - rust-lang/rust#151589 (Add a `documentation` remapping path scope for rustdoc usage) - rust-lang/rust#151639 (Fix broken WASIp1 reference link) - rust-lang/rust#151645 (Update `sysinfo` version to `0.38.0`)
Per my understanding, needed for mut access next line.