-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Doc: remove a "safety note" made obsolete by dropck for TypedArena #24282
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see CONTRIBUTING.md for more information. |
@bors r+ rollup |
📌 Commit c2fa1f7 has been approved by |
@pnkfelix, thinking about this a bit more, I was wondering if dropck really applied here or if unsoundess was still possible with So I tried to see if I could deliberately cause a use-after-free in safe code: #![feature(rustc_private)]
extern crate arena;
use std::cell::Cell;
struct Foo<'a> {
data: Box<u32>,
other: Cell<Option<&'a Foo<'a>>>
}
impl<'a> Drop for Foo<'a> {
fn drop(&mut self) {
let other = self.other.get().unwrap();
println!("Accessing other item’s data = {}", *other.data); // Use after free?
println!("Dropping with data = {}", *self.data);
}
}
fn main() {
let arena = arena::TypedArena::new();
// Create a reference cycle within the arena:
let a = arena.alloc(Foo {
data: Box::new(42),
other: Cell::new(None),
});
let b = arena.alloc(Foo {
data: Box::new(6),
other: Cell::new(None)
});
a.other.set(Some(b));
b.other.set(Some(a));
} This fails to compile with Just because I didn’t manage to find a problem doesn’t prove it doesn’t exist, but I’m slightly more confident about removing this warning now. |
https://botbot.me/mozilla/rust-internals/2015-04-10/?msg=36316959&page=6