mirror of
https://github.com/openharmony/third_party_rust_memoffset.git
synced 2026-07-18 04:17:10 -04:00
Remove const_transmute feature dependency (#45)
Remove `const_transmute` feature flag `const_transmute` has been stabilized on current nightly, see https://github.com/rust-lang/rust/pull/72920. Document `const_fn_transmute` requirement when using `offset_of!` inside a `const fn`. Add test for `offset_of!` inside a `const fn`.
This commit is contained in:
@@ -68,7 +68,12 @@ features = ["unstable_const"]
|
||||
|
||||
Your crate root: (`lib.rs`/`main.rs`)
|
||||
```rust,ignore
|
||||
#![feature(ptr_offset_from, const_ptr_offset_from, const_transmute, const_raw_ptr_deref)]
|
||||
#![feature(ptr_offset_from, const_ptr_offset_from, const_raw_ptr_deref)]
|
||||
```
|
||||
|
||||
Or, if you intend to use `offset_of!` inside a `const fn`:
|
||||
```rust,ignore
|
||||
#![feature(ptr_offset_from, const_fn, const_fn_transmute, const_ptr_offset_from, const_raw_ptr_deref)]
|
||||
```
|
||||
|
||||
and then:
|
||||
|
||||
+2
-1
@@ -61,8 +61,9 @@
|
||||
feature = "unstable_const",
|
||||
feature(
|
||||
ptr_offset_from,
|
||||
const_fn,
|
||||
const_fn_transmute,
|
||||
const_ptr_offset_from,
|
||||
const_transmute,
|
||||
const_raw_ptr_deref,
|
||||
)
|
||||
)]
|
||||
|
||||
@@ -194,4 +194,21 @@ mod tests {
|
||||
|
||||
assert_eq!([0; offset_of!(Foo, b)].len(), 4);
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable_const")]
|
||||
#[test]
|
||||
fn const_fn_offset() {
|
||||
const fn test_fn() -> usize {
|
||||
#[repr(C)]
|
||||
struct Foo {
|
||||
a: u32,
|
||||
b: [u8; 2],
|
||||
c: i64,
|
||||
}
|
||||
|
||||
offset_of!(Foo, b)
|
||||
}
|
||||
|
||||
assert_eq!([0; test_fn()].len(), 4);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user