From 7c247a4c362520a2f3670f4857f6085098f24361 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 28 Mar 2021 18:59:07 +0200 Subject: [PATCH] update feature flags and docs for const offset_of --- README.md | 2 +- src/lib.rs | 3 +-- src/offset_of.rs | 12 ++++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a60f288..62e36a3 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/lib.rs b/src/lib.rs index 454759e..67de5e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, ) )] diff --git a/src/offset_of.rs b/src/offset_of.rs index a363d30..d376498 100644 --- a/src/offset_of.rs +++ b/src/offset_of.rs @@ -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, + } + + assert_eq!([0; offset_of!(Foo, b)].len(), 4); + } + #[cfg(feature = "unstable_const")] #[test] fn const_fn_offset() {