diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f82f7f1..ea6b607 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,6 @@ jobs: - 1.36.0 # Oldest supported with MaybeUninit - 1.40.0 # Oldest supported with cfg(doctest) - 1.51.0 # Oldest supported with ptr::addr_of! - - 1.65.0 # Oldest supported with stable const evaluation (sans cell) - stable - beta - nightly diff --git a/Cargo.toml b/Cargo.toml index 71bdc9e..90620e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "memoffset" -version = "0.8.0" +version = "0.7.1" authors = ["Gilad Naaman "] description = "offset_of functionality for Rust structs." license = "MIT" diff --git a/README.OpenSource b/README.OpenSource index 779da0a..f5a71f8 100644 --- a/README.OpenSource +++ b/README.OpenSource @@ -3,7 +3,7 @@ "Name": "memoffset", "License": "Apache License V2.0", "License File": "LICENSE", - "Version Number": "0.8.0", + "Version Number": "0.7.1", "Owner": "fangting12@huawei.com", "Upstream URL": "https://github.com/Gilnaa/memoffset", "Description": "A Rust library that provides support for calculating offsets in memory." diff --git a/README.md b/README.md index b0bfd10..e297b33 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ C-Like `offset_of` functionality for Rust structs. Introduces the following macros: * `offset_of!` for obtaining the offset of a member of a struct. * `offset_of_tuple!` for obtaining the offset of a member of a tuple. (Requires Rust 1.20+) - * `offset_of_union!` for obtaining the offset of a member of a union. * `span_of!` for obtaining the range that a field, or fields, span. `memoffset` works under `no_std` environments. @@ -17,7 +16,7 @@ Add the following dependency to your `Cargo.toml`: ```toml [dependencies] -memoffset = "0.8" +memoffset = "0.7" ``` These versions will compile fine with rustc versions greater or equal to 1.19. @@ -46,39 +45,20 @@ fn main() { } ``` -## Usage in constants ## -`memoffset` has support for compile-time `offset_of!` on rust>=1.65, or on older nightly compilers. +## Feature flags ## -### Usage on stable Rust ### -Constant evaluation is automatically enabled and avilable on stable compilers starting with rustc 1.65. +### Usage in constants ### +`memoffset` has **experimental** support for compile-time `offset_of!` on a nightly compiler. -This is an incomplete implementation with one caveat: -Due to dependence on [`#![feature(const_refs_to_cell)]`](https://github.com/rust-lang/rust/issues/80384), you cannot get the offset of a `Cell` field in a const-context. - -This means that if need to get the offset of a cell, you'll have to remain on nightly for now. - -### Usage on recent nightlies ### - -If you're using a new-enough nightly and you require the ability to get the offset of a `Cell`, -you'll have to enable the `unstable_const` cargo feature, as well as enabling `const_refs_to_cell` in your crate root. - -Do note that `unstable_const` is an unstable feature that is set to be removed in a future version of `memoffset`. +In order to use it, you must enable the `unstable_const` crate feature and several compiler features. Cargo.toml: ```toml [dependencies.memoffset] -version = "0.8" +version = "0.7" features = ["unstable_const"] ``` -Your crate root: (`lib.rs`/`main.rs`) -```rust,ignore -#![feature(const_refs_to_cell)] -``` - -### Usage on older nightlies ### -In order to use it on an older nightly compiler, you must enable the `unstable_const` crate feature and several compiler features. - Your crate root: (`lib.rs`/`main.rs`) ```rust,ignore #![feature(const_ptr_offset_from, const_refs_to_cell)] diff --git a/build.rs b/build.rs index e18810f..0604c19 100644 --- a/build.rs +++ b/build.rs @@ -19,7 +19,4 @@ fn main() { if ac.probe_rustc_version(1, 51) { println!("cargo:rustc-cfg=raw_ref_macros"); } - if ac.probe_rustc_version(1, 65) { - println!("cargo:rustc-cfg=stable_const"); - } } diff --git a/src/lib.rs b/src/lib.rs index 72736aa..d80ff17 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,10 +57,9 @@ #![no_std] #![cfg_attr( - all(feature = "unstable_const", not(stable_const)), - feature(const_ptr_offset_from) + feature = "unstable_const", + feature(const_ptr_offset_from, const_refs_to_cell) )] -#![cfg_attr(feature = "unstable_const", feature(const_refs_to_cell))] #[macro_use] #[cfg(doctests)] diff --git a/src/offset_of.rs b/src/offset_of.rs index 9ce4ae2..d070181 100644 --- a/src/offset_of.rs +++ b/src/offset_of.rs @@ -46,7 +46,7 @@ macro_rules! _memoffset__let_base_ptr { } /// Macro to compute the distance between two pointers. -#[cfg(any(feature = "unstable_const", stable_const))] +#[cfg(feature = "unstable_const")] #[macro_export] #[doc(hidden)] macro_rules! _memoffset_offset_from_unsafe { @@ -58,7 +58,7 @@ macro_rules! _memoffset_offset_from_unsafe { unsafe { (field as *const u8).offset_from(base as *const u8) as usize } }}; } -#[cfg(not(any(feature = "unstable_const", stable_const)))] +#[cfg(not(feature = "unstable_const"))] #[macro_export] #[doc(hidden)] macro_rules! _memoffset_offset_from_unsafe { @@ -312,7 +312,7 @@ mod tests { assert_eq!(f_ptr as usize + 0, raw_field_union!(f_ptr, Foo, c) as usize); } - #[cfg(any(feature = "unstable_const", stable_const))] + #[cfg(feature = "unstable_const")] #[test] fn const_offset() { #[repr(C)] @@ -337,7 +337,7 @@ mod tests { assert_eq!([0; offset_of!(Foo, b)].len(), 4); } - #[cfg(any(feature = "unstable_const", stable_const))] + #[cfg(feature = "unstable_const")] #[test] fn const_fn_offset() { const fn test_fn() -> usize {