-
Notifications
You must be signed in to change notification settings - Fork 29
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
const_fn usage (with Cell
fields)
#71
Comments
As far as I can see, this also blocks getting offset of any field of a struct with generics e.g.: struct Foo<T> {
t: T,
n: u8,
}
// Both these produce compiler error
impl<T> Foo<T> {
const OFFSET_T: usize = memoffset::offset_of!(Self, t);
const OFFSET_N: usize = memoffset::offset_of!(Self, n);
} Compiler error:
Bounding T to The error seems to come from the const OFFSET_T: usize = {
let uninit = memoffset::__priv::mem::MaybeUninit::<Self>::uninit();
let base_ptr: *const Self = uninit.as_ptr();
// ...
}; Is there any workaround for this on stable Rust? This comment says "Fortunately it can be gotten around by passing in a reference to the |
There will be a work-around soon: Rust 1.77 is slated to ship with a native |
Thanks for coming back so fast Ralf. Amazing! Champagne for everyone! 🎉 While we're talking, can I ask you something else on the same sort of topic? The part which is relevant is where I asked:
|
The blog post says that the hack is no longer needed, it describes the much nicer way to do that. I don't have the hack any more, it was probably some random This is getting off-topic, please reach out to me on Zulip for further questions. |
Previously on memoffset:
Constant evaluation mostly stable with the exception of the inability to take address of a Cell in
const
which still requires nightly and#![feature(const_refs_to_cell)]
.The text was updated successfully, but these errors were encountered: