mirror of
https://gitee.com/openharmony/third_party_rust_memoffset
synced 2024-11-27 01:11:21 +00:00
update feature flags and docs for const offset_of
This commit is contained in:
parent
b9063d1a7a
commit
7c247a4c36
@ -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.
|
||||
|
@ -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,
|
||||
)
|
||||
)]
|
||||
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user