Skip to content

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