Merge pull request #55 from RalfJung/const

update feature flags and docs for const offset_of
This commit is contained in:
Gilad Naaman 2021-03-28 22:29:51 +03:00 committed by GitHub
commit cc587faa9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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() {