-
Notifications
You must be signed in to change notification settings - Fork 11
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
The way ptr_XX and inner_set_XX are implemented is UB #10
Comments
// We do the following instead of `::core::mem::transmute(self)` here
// because we can't `transmute` on fields that involve generics. But I have not yet understood why not just recreate the structure, passing the same fields, but changing the generic parameters. Does it interfere with zero-cost? |
Just a small suggestion, when using Looking back at this comment:
I'm not sure that's correct. You can only transmute between things that have the same size, same applies to casting pointers which have a fixed size known at compile time. Maybe you tried to This code works in rustc version 1.0 https://godbolt.org/z/Yj9jqhEEf: use std::mem;
pub fn x<A, B>(a: &A) {
unsafe {
let _b = mem::transmute::<&A, &B>(a);
}
}
pub struct OrangeBuilder<A, B> {
a: A,
b: B,
}
pub fn y<AUnset, ASet, FieldB>(orange_builder: &OrangeBuilder<AUnset, FieldB>) {
unsafe {
let _ = mem::transmute::<&OrangeBuilder<AUnset, FieldB>, &OrangeBuilder<ASet, FieldB>>(
orange_builder,
);
}
} |
For example
A reference in Rust gurantees that the memory is initialized. You need to use
addr_of_mut
to correctly model this.Somewhat unrleated but I thought I'd mention it.
That looks a lot like transmute. Is there a specific reason not to use transmute here? Also this is UB too, the docs for mem::forget
The text was updated successfully, but these errors were encountered: