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

Create assert_field_offsets! macro #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

nvzqz
Copy link
Owner

@nvzqz nvzqz commented Oct 6, 2019

This introduces assert_field_offsets! for ensuring that given struct fields are at specific offsets.

This current implementation works in Rust 1.37 and 1.38. However, the current beta and nightly compilers fail to perform the constant evaluation. This is not unexpected since the current code creates a reference at mem::align_of::<T>(), where there is no initialized memory. Even though the reference is non-null, dereferencing those addresses is definitely undefined behavior.

I won't be merging this PR as-is. However, I'm interested to learn how this macro could be implemented in a sound way.

See also: Gilnaa/memoffset#24.

(cc @oli-obk @RalfJung)

@RalfJung
Copy link

RalfJung commented Oct 8, 2019

However, I'm interested to learn how this macro could be implemented in a sound way.

Right now, it cannot be implemented soundly. It needs both rust-lang/rust#63810 and rust-lang/rust#64588, as well as allowing &raw in const-context.

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

Successfully merging this pull request may close these issues.

2 participants