forked from steffahn/owning-ref-rs
-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Copied over from here
See the discussion starting here: It is possible to trigger UB in safe code using owning-ref.
Specifically, the assertion in the following snippet by @comex fails, even though it should succeed:
extern crate owning_ref; // 0.4.0
use owning_ref::OwningRef;
use std::cell::Cell;
fn helper(owning_ref: OwningRef<Box<Cell<u8>>, Cell<u8>>) -> u8 {
owning_ref.as_owner().set(10);
owning_ref.set(20);
owning_ref.as_owner().get() // should return 20
}
fn main() {
let val: Box<Cell<u8>> = Box::new(Cell::new(25));
let owning_ref = OwningRef::new(val);
let res = helper(owning_ref);
assert_eq!(res, 20); // assertion fails!
}
Metadata
Metadata
Assignees
Labels
No labels