Skip to content

Commit 78088c4

Browse files
authored
[macros] Clarify size/align behavior of try macros (#2975)
Clarify that, while `try_transmute_{ref,mut}!` check referent validity at runtime, they enforce size and alignment compatibility at compile time. Release 0.8.38. gherrit-pr-id: G2712a29a4b58bdb5d76d4b15763a15f8e8824ae0
1 parent 42ff03b commit 78088c4

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[package]
1616
edition = "2021"
1717
name = "zerocopy"
18-
version = "0.8.37"
18+
version = "0.8.38"
1919
authors = [
2020
"Joshua Liebow-Feeser <joshlf@google.com>",
2121
"Jack Wrenn <jswrenn@amazon.com>",
@@ -112,13 +112,13 @@ __internal_use_only_features_that_work_on_stable = [
112112
]
113113

114114
[dependencies]
115-
zerocopy-derive = { version = "=0.8.37", path = "zerocopy-derive", optional = true }
115+
zerocopy-derive = { version = "=0.8.38", path = "zerocopy-derive", optional = true }
116116

117117
# The "associated proc macro pattern" ensures that the versions of zerocopy and
118118
# zerocopy-derive remain equal, even if the 'derive' feature isn't used.
119119
# See: https://github.com/matklad/macro-dep-test
120120
[target.'cfg(any())'.dependencies]
121-
zerocopy-derive = { version = "=0.8.37", path = "zerocopy-derive" }
121+
zerocopy-derive = { version = "=0.8.38", path = "zerocopy-derive" }
122122

123123
[dev-dependencies]
124124
# FIXME(#381) Remove this dependency once we have our own layout gadgets.
@@ -134,4 +134,4 @@ testutil = { path = "testutil" }
134134
# CI test failures.
135135
trybuild = { version = "=1.0.89", features = ["diff"] }
136136
# In tests, unlike in production, zerocopy-derive is not optional
137-
zerocopy-derive = { version = "=0.8.37", path = "zerocopy-derive" }
137+
zerocopy-derive = { version = "=0.8.38", path = "zerocopy-derive" }

src/macros.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,11 @@ macro_rules! try_transmute {
623623
/// immutable reference of another type of the same size and compatible
624624
/// alignment.
625625
///
626+
/// *Note that while the **value** of the referent is checked for validity at
627+
/// runtime, the **size** and **alignment** are checked at compile time. For
628+
/// conversions which are fallible with respect to size and alignment, see the
629+
/// methods on [`TryFromBytes`].*
630+
///
626631
/// This macro behaves like an invocation of this function:
627632
///
628633
/// ```ignore
@@ -642,6 +647,8 @@ macro_rules! try_transmute {
642647
/// The types `Src` and `Dst` are inferred from the calling context; they cannot
643648
/// be explicitly specified in the macro invocation.
644649
///
650+
/// [`TryFromBytes`]: crate::TryFromBytes
651+
///
645652
/// # Size compatibility
646653
///
647654
/// `try_transmute_ref!` supports transmuting between `Sized` types, between
@@ -744,6 +751,11 @@ macro_rules! try_transmute_ref {
744751
/// Conditionally transmutes a mutable reference of one type to a mutable
745752
/// reference of another type of the same size and compatible alignment.
746753
///
754+
/// *Note that while the **value** of the referent is checked for validity at
755+
/// runtime, the **size** and **alignment** are checked at compile time. For
756+
/// conversions which are fallible with respect to size and alignment, see the
757+
/// methods on [`TryFromBytes`].*
758+
///
747759
/// This macro behaves like an invocation of this function:
748760
///
749761
/// ```ignore
@@ -763,6 +775,8 @@ macro_rules! try_transmute_ref {
763775
/// The types `Src` and `Dst` are inferred from the calling context; they cannot
764776
/// be explicitly specified in the macro invocation.
765777
///
778+
/// [`TryFromBytes`]: crate::TryFromBytes
779+
///
766780
/// # Size compatibility
767781
///
768782
/// `try_transmute_mut!` supports transmuting between `Sized` types, between

zerocopy-derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[package]
1010
edition = "2021"
1111
name = "zerocopy-derive"
12-
version = "0.8.37"
12+
version = "0.8.38"
1313
authors = ["Joshua Liebow-Feeser <joshlf@google.com>", "Jack Wrenn <jswrenn@amazon.com>"]
1414
description = "Custom derive for traits from the zerocopy crate"
1515
license = "BSD-2-Clause OR Apache-2.0 OR MIT"

0 commit comments

Comments
 (0)