-
Notifications
You must be signed in to change notification settings - Fork 2
Closed
Description
As the Gc type implements DerefMut, one can write the following safe code:
let gc_val = Gc::new(5);
let ptr1 = gc_val;
let ptr2 = gc_val;
let ref1 = ptr1.deref_mut();
let ref2 = ptr2.deref_mut();
At this point, there are now two simultaneous mutable references to the same value, which is undefined behaviour.
I would recommend the DerefMut trait be removed from Gc<T> and to leave only Deref, as only immutable references can be safely created for a type managing shared ownership. Those wishing to add mutability should wrap the value in a RefCell<T>, as one would with Rc<T>.
Metadata
Metadata
Assignees
Labels
No labels