diff options
author | Jeff Vander Stoep <jeffv@google.com> | 2023-02-03 15:12:38 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-02-03 15:12:38 +0000 |
commit | 8d78029841d6438f0f262d46eff791b65de5e530 (patch) | |
tree | 570f63cdcbfe97dbe60cb0273e032d078dbbf6ca | |
parent | 92d7858e3bdf1928f710bd53c479bd02504c96e4 (diff) | |
parent | 88166c7f4d15ca58c507bae360194a14c011f1d3 (diff) | |
download | memoffset-8d78029841d6438f0f262d46eff791b65de5e530.tar.gz |
Upgrade memoffset to 0.8.0 am: 0d0d25cb12 am: 6817016059 am: 88166c7f4d
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/memoffset/+/2419084
Change-Id: I36a5d01ac3c1569464e03ca24bcd9c0bf0af61a9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | .github/workflows/ci.yml | 1 | ||||
-rw-r--r-- | Android.bp | 6 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | Cargo.toml.orig | 2 | ||||
-rw-r--r-- | METADATA | 10 | ||||
-rw-r--r-- | README.md | 32 | ||||
-rw-r--r-- | build.rs | 3 | ||||
-rw-r--r-- | src/lib.rs | 5 | ||||
-rw-r--r-- | src/offset_of.rs | 8 |
10 files changed, 49 insertions, 22 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 057a882..161d06e 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "d8accb76712984e2ab069193f392e5a7b6c5e78c" + "sha1": "0fac3ac6642dd017a36268c4cdba2f04ec050d11" }, "path_in_vcs": "" }
\ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea6b607..f82f7f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,7 @@ 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 @@ -23,7 +23,7 @@ rust_library { host_supported: true, crate_name: "memoffset", cargo_env_compat: true, - cargo_pkg_version: "0.7.1", + cargo_pkg_version: "0.8.0", srcs: ["src/lib.rs"], edition: "2015", features: ["default"], @@ -32,6 +32,7 @@ rust_library { "doctests", "maybe_uninit", "raw_ref_macros", + "stable_const", "tuple_ty", ], apex_available: [ @@ -49,7 +50,7 @@ rust_test { host_supported: true, crate_name: "memoffset", cargo_env_compat: true, - cargo_pkg_version: "0.7.1", + cargo_pkg_version: "0.8.0", srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -63,6 +64,7 @@ rust_test { "doctests", "maybe_uninit", "raw_ref_macros", + "stable_const", "tuple_ty", ], } @@ -11,7 +11,7 @@ [package] name = "memoffset" -version = "0.7.1" +version = "0.8.0" authors = ["Gilad Naaman <gilad.naaman@gmail.com>"] description = "offset_of functionality for Rust structs." readme = "README.md" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 90620e2..71bdc9e 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "memoffset" -version = "0.7.1" +version = "0.8.0" authors = ["Gilad Naaman <gilad.naaman@gmail.com>"] description = "offset_of functionality for Rust structs." license = "MIT" @@ -11,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/memoffset/memoffset-0.7.1.crate" + value: "https://static.crates.io/crates/memoffset/memoffset-0.8.0.crate" } - version: "0.7.1" + version: "0.8.0" license_type: NOTICE last_upgrade_date { - year: 2022 - month: 12 - day: 12 + year: 2023 + month: 2 + day: 3 } } @@ -7,6 +7,7 @@ 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. @@ -16,7 +17,7 @@ Add the following dependency to your `Cargo.toml`: ```toml [dependencies] -memoffset = "0.7" +memoffset = "0.8" ``` These versions will compile fine with rustc versions greater or equal to 1.19. @@ -45,21 +46,40 @@ fn main() { } ``` -## Feature flags ## +## Usage in constants ## +`memoffset` has support for compile-time `offset_of!` on rust>=1.65, or on older nightly compilers. -### Usage in constants ### -`memoffset` has **experimental** support for compile-time `offset_of!` on a nightly compiler. +### Usage on stable Rust ### +Constant evaluation is automatically enabled and avilable on stable compilers starting with rustc 1.65. -In order to use it, you must enable the `unstable_const` crate feature and several compiler features. +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`. Cargo.toml: ```toml [dependencies.memoffset] -version = "0.7" +version = "0.8" 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)] ``` @@ -19,4 +19,7 @@ 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"); + } } @@ -58,9 +58,10 @@ // ANDROID: include standard library to build as a dylib //#![no_std] #![cfg_attr( - feature = "unstable_const", - feature(const_ptr_offset_from, const_refs_to_cell) + all(feature = "unstable_const", not(stable_const)), + feature(const_ptr_offset_from) )] +#![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 d070181..9ce4ae2 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(feature = "unstable_const")] +#[cfg(any(feature = "unstable_const", stable_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(feature = "unstable_const"))] +#[cfg(not(any(feature = "unstable_const", stable_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(feature = "unstable_const")] + #[cfg(any(feature = "unstable_const", stable_const))] #[test] fn const_offset() { #[repr(C)] @@ -337,7 +337,7 @@ mod tests { assert_eq!([0; offset_of!(Foo, b)].len(), 4); } - #[cfg(feature = "unstable_const")] + #[cfg(any(feature = "unstable_const", stable_const))] #[test] fn const_fn_offset() { const fn test_fn() -> usize { |