-
Notifications
You must be signed in to change notification settings - Fork 35
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
ouroboros is in conflict with noalias
#33
Comments
I don't think this has the same problem. When a field is mutably referenced, the functions generated prevent accessing the field directly. In your example, the data contained in |
Even if the field is not accessible in the public API, it is still considered mutably borrowed if the outer #[self_referencing]
struct MyStruct {
float_data: Box<Cell<f32>>,
#[borrows(float_data)]
float_reference: &'this Cell<f32>,
}
fn helper(s: MyStruct) -> f32 {
s.borrow_float_data().set(10);
s.borrow_float_reference().set(20);
s.borrow_float_data().get()
}
fn main() {
let res = helper(MyStruct::new(Box::new(Cell::new(0)), |r| r));
assert_eq!(res, 20);
} I do not know if this particular example causes miscompilations (you should check on Nightly), but it is certainly UB, because the compiler thinks that:
But that assumption broken by this crate. In terms of solutions, you could require the field which is borrowed from to implement |
@Kestrer thanks for your explanation, I think I understand the problem now. I prefer the solution of wrapping borrowed fields in #[self_referencing]
struct Example {
data: i32,
#[borrows(data)]
dref: &'this i32,
} It would also resolve the issue that lead to the creation of #[self_referencing]
struct Example {
data: String,
#[borrows(data)]
parser: Parser<'this>,
#[borrows(parser)]
parsed: Parsed<'this. 'this>,
} |
Version |
See Kimundi/owning-ref-rs#49
The text was updated successfully, but these errors were encountered: