update feature flags and docs for const offset_of

This commit is contained in:
Ralf Jung 2021-03-28 18:59:07 +02:00
parent b9063d1a7a
commit 7c247a4c36
3 changed files with 14 additions and 3 deletions

View File

@ -69,7 +69,7 @@ features = ["unstable_const"]
Your crate root: (`lib.rs`/`main.rs`)
```rust,ignore
#![feature(ptr_offset_from, const_ptr_offset_from, const_maybe_uninit_as_ptr, const_raw_ptr_deref)]
#![feature(const_ptr_offset_from, const_maybe_uninit_as_ptr, const_raw_ptr_deref, const_refs_to_cell)]
```
If you intend to use `offset_of!` inside a `const fn`, also add the `const_fn` compiler feature.

View File

@ -60,11 +60,10 @@
#![cfg_attr(
feature = "unstable_const",
feature(
ptr_offset_from,
const_fn,
const_ptr_offset_from,
const_maybe_uninit_as_ptr,
const_raw_ptr_deref,
const_refs_to_cell,
)
)]

View File

@ -253,6 +253,18 @@ mod tests {
assert_eq!([0; offset_of!(Foo, b)].len(), 4);
}
#[cfg(feature = "unstable_const")]
#[test]
fn const_offset_interior_mutable() {
#[repr(C)]
struct Foo {
a: u32,
b: core::cell::Cell<u32>,
}
assert_eq!([0; offset_of!(Foo, b)].len(), 4);
}
#[cfg(feature = "unstable_const")]
#[test]
fn const_fn_offset() {