Skip to content

Commit

Permalink
Remove const_transmute feature dependency (#45)
Browse files Browse the repository at this point in the history
Remove `const_transmute` feature flag

`const_transmute` has been stabilized on current nightly, see rust-lang/rust#72920.
Document `const_fn_transmute` requirement when using `offset_of!` inside a `const fn`.
Add test for `offset_of!` inside a `const fn`.
  • Loading branch information
RSSchermer authored Jul 30, 2020
1 parent 8ec2862 commit 9520967
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)]
Expand Down
17 changes: 17 additions & 0 deletions src/offset_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 9520967

Please sign in to comment.