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:
Roland
2020-07-31 00:21:18 +02:00
committed by GitHub
parent e8ee92203a
commit 608e11823e
3 changed files with 25 additions and 2 deletions
+6 -1
View File
@@ -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
View File
@@ -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,
)
)]
+17
View File
@@ -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);
}
}