Skip to content

Commit cdead15

Browse files
authored
[macro_util] Rename from derive_util, include more (#455)
Include macro utilities - namely, re-exports of core symbols used by macro-generated code. Release 0.7.7 to work around a cargo-semver-checks false positive; see #455 (comment).
1 parent 78062fc commit cdead15

File tree

5 files changed

+30
-28
lines changed

5 files changed

+30
-28
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[package]
1212
edition = "2021"
1313
name = "zerocopy"
14-
version = "0.7.6"
14+
version = "0.7.7"
1515
authors = ["Joshua Liebow-Feeser <joshlf@google.com>"]
1616
description = "Utilities for zero-copy parsing and serialization"
1717
license = "BSD-2-Clause"
@@ -41,7 +41,7 @@ simd-nightly = ["simd"]
4141
__internal_use_only_features_that_work_on_stable = ["alloc", "derive", "simd"]
4242

4343
[dependencies]
44-
zerocopy-derive = { version = "=0.7.6", path = "zerocopy-derive", optional = true }
44+
zerocopy-derive = { version = "=0.7.7", path = "zerocopy-derive", optional = true }
4545

4646
[dependencies.byteorder]
4747
version = "1.3"
@@ -52,7 +52,7 @@ optional = true
5252
# zerocopy-derive remain equal, even if the 'derive' feature isn't used.
5353
# See: https://github.com/matklad/macro-dep-test
5454
[target.'cfg(any())'.dependencies]
55-
zerocopy-derive = { version = "=0.7.6", path = "zerocopy-derive" }
55+
zerocopy-derive = { version = "=0.7.7", path = "zerocopy-derive" }
5656

5757
[dev-dependencies]
5858
assert_matches = "1.5"
@@ -67,4 +67,4 @@ testutil = { path = "testutil" }
6767
# CI test failures.
6868
trybuild = "=1.0.80"
6969
# In tests, unlike in production, zerocopy-derive is not optional
70-
zerocopy-derive = { version = "=0.7.6", path = "zerocopy-derive" }
70+
zerocopy-derive = { version = "=0.7.7", path = "zerocopy-derive" }

src/lib.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,8 @@ mod macros;
170170

171171
#[cfg(feature = "byteorder")]
172172
pub mod byteorder;
173-
#[cfg(any(feature = "derive", test))]
174173
#[doc(hidden)]
175-
pub mod derive_util;
174+
pub mod macro_util;
176175
mod util;
177176
// TODO(#252): If we make this pub, come up with a better name.
178177
mod wrappers;
@@ -1628,10 +1627,6 @@ mod simd {
16281627
simd_arch_mod!(arm, int8x4_t, uint8x4_t);
16291628
}
16301629

1631-
// Used in `transmute!` below.
1632-
#[doc(hidden)]
1633-
pub use core::mem::transmute as __real_transmute;
1634-
16351630
/// Safely transmutes a value of one type to a value of another type of the same
16361631
/// size.
16371632
///
@@ -1666,14 +1661,15 @@ macro_rules! transmute {
16661661
// We know this transmute is safe thanks to the `AsBytes` and
16671662
// `FromBytes` bounds enforced by the `false` branch.
16681663
//
1669-
// We use `$crate::__real_transmute` because we know it will always
1670-
// be available for crates which are using the 2015 edition of Rust.
1671-
// By contrast, if we were to use `std::mem::transmute`, this macro
1672-
// would not work for such crates in `no_std` contexts, and if we
1673-
// were to use `core::mem::transmute`, this macro would not work in
1674-
// `std` contexts in which `core` was not manually imported. This is
1675-
// not a problem for 2018 edition crates.
1676-
unsafe { $crate::__real_transmute(e) }
1664+
// We use this reexport of `core::mem::transmute` because we know it
1665+
// will always be available for crates which are using the 2015
1666+
// edition of Rust. By contrast, if we were to use
1667+
// `std::mem::transmute`, this macro would not work for such crates
1668+
// in `no_std` contexts, and if we were to use
1669+
// `core::mem::transmute`, this macro would not work in `std`
1670+
// contexts in which `core` was not manually imported. This is not a
1671+
// problem for 2018 edition crates.
1672+
unsafe { $crate::macro_util::core_reexport::mem::transmute(e) }
16771673
}
16781674
}}
16791675
}

src/derive_util.rs renamed to src/macro_util.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
//! Utilities used by `zerocopy-derive`.
5+
//! Utilities used by macros and by `zerocopy-derive`.
66
//!
7-
//! These are defined in `zerocopy` rather than in code generated by
8-
//! `zerocopy-derive` so that they can be compiled once rather than recompiled
9-
//! for every pair of type and trait (in other words, if they were defined in
10-
//! generated code, then deriving `AsBytes` and `FromBytes` on three different
11-
//! types would result in the code in question being emitted and compiled six
12-
//! different times).
7+
//! These are defined here `zerocopy` rather than in code generated by macros or
8+
//! by `zerocopy-derive` so that they can be compiled once rather than
9+
//! recompiled for every invocation (e.g., if they were defined in generated
10+
//! code, then deriving `AsBytes` and `FromBytes` on three different types would
11+
//! result in the code in question being emitted and compiled six different
12+
//! times).
1313
1414
#![allow(missing_debug_implementations)]
1515

@@ -63,6 +63,12 @@ macro_rules! union_has_padding {
6363
};
6464
}
6565

66+
pub mod core_reexport {
67+
pub mod mem {
68+
pub use core::mem::transmute;
69+
}
70+
}
71+
6672
#[cfg(test)]
6773
mod tests {
6874
use crate::util::testutil::*;

zerocopy-derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[package]
66
edition = "2021"
77
name = "zerocopy-derive"
8-
version = "0.7.6"
8+
version = "0.7.7"
99
authors = ["Joshua Liebow-Feeser <joshlf@google.com>"]
1010
description = "Custom derive for traits from the zerocopy crate"
1111
license = "BSD-2-Clause"

zerocopy-derive/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,8 @@ fn impl_block<D: DataExt>(
530530
let fields = field_types.iter();
531531
let validator_macro = check.validator_macro_ident();
532532
parse_quote!(
533-
zerocopy::derive_util::HasPadding<#type_ident, {zerocopy::#validator_macro!(#type_ident, #(#fields),*)}>:
534-
zerocopy::derive_util::ShouldBe<false>
533+
zerocopy::macro_util::HasPadding<#type_ident, {zerocopy::#validator_macro!(#type_ident, #(#fields),*)}>:
534+
zerocopy::macro_util::ShouldBe<false>
535535
)
536536
});
537537

0 commit comments

Comments
 (0)