Skip to content
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

OwningRef is in conflict with noalias #3

Open
noamtashma opened this issue Nov 5, 2023 · 2 comments
Open

OwningRef is in conflict with noalias #3

noamtashma opened this issue Nov 5, 2023 · 2 comments

Comments

@noamtashma
Copy link
Owner

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
Copy link
Owner Author

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

@luketpeterson
Copy link

I realized rust-lang/rfcs#3336 is now merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants