From 4c87a5971e2b203d48415e2ae696c6b7028b1db0 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Wed, 8 Jul 2026 11:25:57 -0700 Subject: [PATCH 1/2] Add baseline inline annotations --- zerocopy/src/layout.rs | 1 + zerocopy/src/util/mod.rs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/zerocopy/src/layout.rs b/zerocopy/src/layout.rs index 6eff4ee09d..5747f17c50 100644 --- a/zerocopy/src/layout.rs +++ b/zerocopy/src/layout.rs @@ -71,6 +71,7 @@ impl SizeInfo { /// Attempts to create a `SizeInfo` from `Self` in which `elem_size` is a /// `NonZeroUsize`. If `elem_size` is 0, returns `None`. #[allow(unused)] + #[inline] #[cfg_attr(zerocopy_inline_always, inline(always))] const fn try_to_nonzero_elem_size(&self) -> Option> { Some(match *self { diff --git a/zerocopy/src/util/mod.rs b/zerocopy/src/util/mod.rs index fedd8ff679..5e4e41bd83 100644 --- a/zerocopy/src/util/mod.rs +++ b/zerocopy/src/util/mod.rs @@ -150,6 +150,7 @@ pub(crate) fn validate_aligned_to(t: T) -> Result<(), Alignment // Ensures that we add the minimum required padding. kani::ensures(|&p| p < align.get()), )] +#[inline] #[cfg_attr(zerocopy_inline_always, inline(always))] pub(crate) const fn padding_needed_for(len: usize, align: NonZeroUsize) -> usize { #[cfg(kani)] @@ -252,6 +253,7 @@ pub(crate) const fn round_down_to_next_multiple_of_alignment( n & mask } +#[inline] #[cfg_attr(zerocopy_inline_always, inline(always))] pub(crate) const fn max(a: NonZeroUsize, b: NonZeroUsize) -> NonZeroUsize { if a.get() < b.get() { @@ -261,6 +263,7 @@ pub(crate) const fn max(a: NonZeroUsize, b: NonZeroUsize) -> NonZeroUsize { } } +#[inline] #[cfg_attr(zerocopy_inline_always, inline(always))] pub(crate) const fn min(a: NonZeroUsize, b: NonZeroUsize) -> NonZeroUsize { if a.get() > b.get() { From efbf23978ac1285ea7c1fd8c24626218e9664d57 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Wed, 8 Jul 2026 12:35:15 -0700 Subject: [PATCH 2/2] Gate baseline inline annotations --- zerocopy/src/layout.rs | 2 +- zerocopy/src/util/mod.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/zerocopy/src/layout.rs b/zerocopy/src/layout.rs index 5747f17c50..d58786d637 100644 --- a/zerocopy/src/layout.rs +++ b/zerocopy/src/layout.rs @@ -71,7 +71,7 @@ impl SizeInfo { /// Attempts to create a `SizeInfo` from `Self` in which `elem_size` is a /// `NonZeroUsize`. If `elem_size` is 0, returns `None`. #[allow(unused)] - #[inline] + #[cfg_attr(not(zerocopy_inline_always), inline)] #[cfg_attr(zerocopy_inline_always, inline(always))] const fn try_to_nonzero_elem_size(&self) -> Option> { Some(match *self { diff --git a/zerocopy/src/util/mod.rs b/zerocopy/src/util/mod.rs index 5e4e41bd83..bd0d83e78c 100644 --- a/zerocopy/src/util/mod.rs +++ b/zerocopy/src/util/mod.rs @@ -150,7 +150,7 @@ pub(crate) fn validate_aligned_to(t: T) -> Result<(), Alignment // Ensures that we add the minimum required padding. kani::ensures(|&p| p < align.get()), )] -#[inline] +#[cfg_attr(not(zerocopy_inline_always), inline)] #[cfg_attr(zerocopy_inline_always, inline(always))] pub(crate) const fn padding_needed_for(len: usize, align: NonZeroUsize) -> usize { #[cfg(kani)] @@ -253,7 +253,7 @@ pub(crate) const fn round_down_to_next_multiple_of_alignment( n & mask } -#[inline] +#[cfg_attr(not(zerocopy_inline_always), inline)] #[cfg_attr(zerocopy_inline_always, inline(always))] pub(crate) const fn max(a: NonZeroUsize, b: NonZeroUsize) -> NonZeroUsize { if a.get() < b.get() { @@ -263,7 +263,7 @@ pub(crate) const fn max(a: NonZeroUsize, b: NonZeroUsize) -> NonZeroUsize { } } -#[inline] +#[cfg_attr(not(zerocopy_inline_always), inline)] #[cfg_attr(zerocopy_inline_always, inline(always))] pub(crate) const fn min(a: NonZeroUsize, b: NonZeroUsize) -> NonZeroUsize { if a.get() > b.get() {