noamtashma / owning-ref-rs

A library for creating references that carry their owner with them.
MIT License
6 stars 1 forks source link

OwningRef is in conflict with `noalias` #3

Open noamtashma opened 10 months ago

noamtashma commented 10 months ago

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!
}
noamtashma commented 10 months ago

Currently on my computer, this piece of code runs correctly, but miri under stacked borrows and under tree borrows still errors.