Rust fixes for v7.2 (2nd)

Toolchain and infrastructure:
 
  - 'zerocopy' crates: update to v0.8.54 to fix a modpost error under
    'CONFIG_CC_OPTIMIZE_FOR_SIZE=y'.
 
    There are actually two updates in the PR: the one to v0.8.52 is
    fairly large and was originally not intended for a fixes PR, but the
    actual fix landed in the v0.8.54 one. Thus I included both here.
 
    The v0.8.52 update includes two things upstream added for us:
    '--cfg no_fp_fmt_parse' to avoid a local workaround, and the new
    'most_traits' feature.
 
    The good news is that, after these updates, the delta with upstream
    is now trivial: only an identifier prefix change and the SPDX
    parentheses.
 
  - Fix an objtool warning by adding one more 'noreturn' function for
    Rust 1.99.0 (expected 2026-10-01).
 
  - Clean up new 'semicolon_in_expressions_from_macros' lint errors for
    Rust 1.99.0 (expected 2026-10-01). The lint can be allowed, but it
    will be a hard error at some point in the future anyway, so clean it
    up now.
 
  - Locally allow new 'suspicious_runtime_symbol_definitions' lint for
    Rust 1.98.0 (expected 2026-08-20).
 
  - Globally allow 'clippy::unwrap_or_default' lint since it relies on
    optimizations -- under 'CONFIG_CC_OPTIMIZE_FOR_SIZE=y' it does not
    work well.
 
 'kernel' crate:
 
  - 'time' module: fix 'Delta::as_micros_ceil()' to round negative values
    correctly.
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEPjU5OPd5QIZ9jqqOGXyLc2htIW0FAmpk6V4ACgkQGXyLc2ht
 IW24OQ/7B2pQtg8IE/6fvkPO7I+EPGknkiutPczrh0HFJ2x0rSaC69NVjkV3d5nq
 KWk1zOPPzxMoOeIEOR/e8iAMfo9B093mlohappwMKLZGju2x+K6JA+rn6HsvTLiv
 fGgjM7hq3B7ExBCon7qDQLYh6cib9T90e9IJrE8rnitbJ8QkUSqXTwCqUbkN7pOt
 U5GUX9yHxo9slc9XYy3AC8aifqaBNeUWzfn6a7DN7nLUNhm5AYiYyduvU6QZQ1kR
 ezinZn3Jqv+VrpXcuM2x2iMMJCdFILzXdnrhPWoT8whc9GzNWVArkSIYFefvjgvK
 Yb+gppVjEuKwsT81eoMwD9edD+wL/4MSU6lnW4eN0EhgECSy7HZs2Jjv1UIrPPSH
 ZvVp6Bzn0nuXed4fh+mrqvwmltqnDpVK06c/q6M8u5mQ/HURwCsh43M7X7S4Sm0p
 X8AutCjsWj+uP44ZnC/Y5p/r3tFl+HM55YT/favb54Xzq+SDrMtSQ7HFM7CZaDHd
 g1B/SBlCTs1O1htqNDWqzew8HdoLfRueZf9tRnTCYSlvOgjSgBB9561m2wfgVE86
 yrwPnaYZeipny2hVh+iCiZGDvrqKh+r4nMB8R8X61qjWC7/szjsxs3IiCUpPpMJB
 3omYUm3nOxzZjYp9uK0E+YW+BITjC8VrP6XWUnzedfas1bds63k=
 =4BpZ
 -----END PGP SIGNATURE-----

Merge tag 'rust-fixes-7.2-2' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux

Pull rust fixes from Miguel Ojeda:
 "Toolchain and infrastructure:

   - 'zerocopy' crates: update to v0.8.54 to fix a modpost error under
     'CONFIG_CC_OPTIMIZE_FOR_SIZE=y'.

     There are actually two updates in the PR: the one to v0.8.52 is
     fairly large and was originally not intended for a fixes PR, but the
     actual fix landed in the v0.8.54 one. Thus I included both here.

     The v0.8.52 update includes two things upstream added for us:
     '--cfg no_fp_fmt_parse' to avoid a local workaround, and the new
     'most_traits' feature.

     The good news is that, after these updates, the delta with upstream
     is now trivial: only an identifier prefix change and the SPDX
     parentheses.

   - Fix an objtool warning by adding one more 'noreturn' function for
     Rust 1.99.0 (expected 2026-10-01).

   - Clean up new 'semicolon_in_expressions_from_macros' lint errors for
     Rust 1.99.0 (expected 2026-10-01). The lint can be allowed, but it
     will be a hard error at some point in the future anyway, so clean it
     up now.

   - Locally allow new 'suspicious_runtime_symbol_definitions' lint for
     Rust 1.98.0 (expected 2026-08-20).

   - Globally allow 'clippy::unwrap_or_default' lint since it relies on
     optimizations -- under 'CONFIG_CC_OPTIMIZE_FOR_SIZE=y' it does not
     work well.

  'kernel' crate:

   - 'time' module: fix 'Delta::as_micros_ceil()' to round negative values
     correctly"

* tag 'rust-fixes-7.2-2' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux:
  rust: time: fix as_micros_ceil() to round correctly for negative Delta
  rust: device: avoid trailing ; in printing macros
  objtool/rust: add one more `noreturn` Rust function for Rust 1.99.0
  rust: zerocopy: update to v0.8.54
  rust: zerocopy: update to v0.8.52
  rust: allow `clippy::unwrap_or_default` globally
  rust: allow `suspicious_runtime_symbol_definitions` lint for Rust >= 1.98
This commit is contained in:
Linus Torvalds 2026-07-25 10:15:23 -07:00
commit 3dab139d47
39 changed files with 217 additions and 90 deletions

View File

@ -475,6 +475,10 @@ KBUILD_USERLDFLAGS := $(USERLDFLAGS)
# These flags apply to all Rust code in the tree, including the kernel and
# host programs.
#
# `-Aclippy::unwrap_or_default`: the lint is buggy [1] and ignores our
# MSRV. It can trigger depending on the optimization level.
# [1] https://github.com/rust-lang/rust-clippy/issues/17379
export rust_common_flags := --edition=2021 \
-Zbinary_dep_depinfo=y \
-Astable_features \
@ -503,6 +507,7 @@ export rust_common_flags := --edition=2021 \
-Aclippy::uninlined_format_args \
-Wclippy::unnecessary_safety_comment \
-Wclippy::unnecessary_safety_doc \
-Aclippy::unwrap_or_default \
-Wrustdoc::missing_crate_level_docs \
-Wrustdoc::unescaped_backticks

View File

@ -190,6 +190,9 @@ config RUSTC_HAS_FILE_WITH_NUL
config RUSTC_HAS_FILE_AS_C_STR
def_bool RUSTC_VERSION >= 109100
config RUSTC_HAS_SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS
def_bool RUSTC_VERSION >= 109800
config PAHOLE_VERSION
int
default "$(PAHOLE_VERSION)"

View File

@ -84,11 +84,15 @@ core-flags := \
--edition=$(core-edition) \
$(call cfgs-to-flags,$(core-cfgs))
zerocopy-cfgs := \
no_fp_fmt_parse
zerocopy-flags := \
--cap-lints=allow
--cap-lints=allow \
$(call cfgs-to-flags,$(zerocopy-cfgs))
zerocopy-envs := \
CARGO_PKG_VERSION=0.8.50
CARGO_PKG_VERSION=0.8.54
proc_macro2-cfgs := \
feature="proc-macro" \
@ -128,11 +132,15 @@ syn-flags := \
--extern quote \
$(call cfgs-to-flags,$(syn-cfgs))
zerocopy_derive-cfgs := \
zerocopy_unstable_linux
zerocopy_derive-flags := \
--cap-lints=allow \
--extern proc_macro2 \
--extern quote \
--extern syn
--extern syn \
$(call cfgs-to-flags,$(zerocopy_derive-cfgs))
pin_init_internal-cfgs := \
kernel USE_RUSTC_FEATURES
@ -644,9 +652,11 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
rust-analyzer:
$(Q)MAKEFLAGS= $(srctree)/scripts/generate_rust_analyzer.py \
--cfgs='core=$(core-cfgs)' $(core-edition) \
--cfgs='zerocopy=$(zerocopy-cfgs)' \
--cfgs='proc_macro2=$(proc_macro2-cfgs)' \
--cfgs='quote=$(quote-cfgs)' \
--cfgs='syn=$(syn-cfgs)' \
--cfgs='zerocopy_derive=$(zerocopy_derive-cfgs)' \
--cfgs='pin_init_internal=$(pin_init_internal-cfgs)' \
--cfgs='pin_init=$(pin_init-cfgs)' \
--envs='zerocopy=$(zerocopy-envs)' \

View File

@ -27,6 +27,10 @@
#[allow(clippy::ref_as_ptr)]
#[allow(clippy::undocumented_unsafe_blocks)]
#[cfg_attr(CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES, allow(unnecessary_transmutes))]
#[cfg_attr(
CONFIG_RUSTC_HAS_SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS,
allow(suspicious_runtime_symbol_definitions)
)]
mod bindings_raw {
use pin_init::{MaybeZeroable, Zeroable};

View File

@ -708,9 +708,7 @@ macro_rules! impl_device_context_into_aref {
#[macro_export]
macro_rules! dev_printk {
($method:ident, $dev:expr, $($f:tt)*) => {
{
$crate::device::Device::$method($dev.as_ref(), $crate::prelude::fmt!($($f)*))
}
$crate::device::Device::$method($dev.as_ref(), $crate::prelude::fmt!($($f)*))
}
}
@ -737,7 +735,7 @@ macro_rules! dev_printk {
/// ```
#[macro_export]
macro_rules! dev_emerg {
($($f:tt)*) => { $crate::dev_printk!(pr_emerg, $($f)*); }
($($f:tt)*) => { $crate::dev_printk!(pr_emerg, $($f)*) }
}
/// Prints an alert-level message (level 1) prefixed with device information.
@ -763,7 +761,7 @@ macro_rules! dev_emerg {
/// ```
#[macro_export]
macro_rules! dev_alert {
($($f:tt)*) => { $crate::dev_printk!(pr_alert, $($f)*); }
($($f:tt)*) => { $crate::dev_printk!(pr_alert, $($f)*) }
}
/// Prints a critical-level message (level 2) prefixed with device information.
@ -789,7 +787,7 @@ macro_rules! dev_alert {
/// ```
#[macro_export]
macro_rules! dev_crit {
($($f:tt)*) => { $crate::dev_printk!(pr_crit, $($f)*); }
($($f:tt)*) => { $crate::dev_printk!(pr_crit, $($f)*) }
}
/// Prints an error-level message (level 3) prefixed with device information.
@ -815,7 +813,7 @@ macro_rules! dev_crit {
/// ```
#[macro_export]
macro_rules! dev_err {
($($f:tt)*) => { $crate::dev_printk!(pr_err, $($f)*); }
($($f:tt)*) => { $crate::dev_printk!(pr_err, $($f)*) }
}
/// Prints a warning-level message (level 4) prefixed with device information.
@ -841,7 +839,7 @@ macro_rules! dev_err {
/// ```
#[macro_export]
macro_rules! dev_warn {
($($f:tt)*) => { $crate::dev_printk!(pr_warn, $($f)*); }
($($f:tt)*) => { $crate::dev_printk!(pr_warn, $($f)*) }
}
/// Prints a notice-level message (level 5) prefixed with device information.
@ -867,7 +865,7 @@ macro_rules! dev_warn {
/// ```
#[macro_export]
macro_rules! dev_notice {
($($f:tt)*) => { $crate::dev_printk!(pr_notice, $($f)*); }
($($f:tt)*) => { $crate::dev_printk!(pr_notice, $($f)*) }
}
/// Prints an info-level message (level 6) prefixed with device information.
@ -893,7 +891,7 @@ macro_rules! dev_notice {
/// ```
#[macro_export]
macro_rules! dev_info {
($($f:tt)*) => { $crate::dev_printk!(pr_info, $($f)*); }
($($f:tt)*) => { $crate::dev_printk!(pr_info, $($f)*) }
}
/// Prints a debug-level message (level 7) prefixed with device information.
@ -919,5 +917,5 @@ macro_rules! dev_info {
/// ```
#[macro_export]
macro_rules! dev_dbg {
($($f:tt)*) => { $crate::dev_printk!(pr_dbg, $($f)*); }
($($f:tt)*) => { $crate::dev_printk!(pr_dbg, $($f)*) }
}

View File

@ -441,15 +441,22 @@ pub const fn as_nanos(self) -> i64 {
/// to the value in the [`Delta`].
#[inline]
pub fn as_micros_ceil(self) -> i64 {
let n = self.as_nanos();
let n = if n >= 0 {
n.saturating_add(NSEC_PER_USEC - 1)
} else {
n
};
#[cfg(CONFIG_64BIT)]
{
self.as_nanos().saturating_add(NSEC_PER_USEC - 1) / NSEC_PER_USEC
n / NSEC_PER_USEC
}
#[cfg(not(CONFIG_64BIT))]
// SAFETY: It is always safe to call `ktime_to_us()` with any value.
unsafe {
bindings::ktime_to_us(self.as_nanos().saturating_add(NSEC_PER_USEC - 1))
bindings::ktime_to_us(n)
}
}

View File

@ -24,6 +24,10 @@
unsafe_op_in_unsafe_fn
)]
#![cfg_attr(CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES, allow(unnecessary_transmutes))]
#![cfg_attr(
CONFIG_RUSTC_HAS_SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS,
allow(suspicious_runtime_symbol_definitions)
)]
#![feature(cfi_encoding)]
// Manual definition of blocklisted types.

View File

@ -1,14 +1,14 @@
# `zerocopy-derive`
These source files come from the Rust `zerocopy-derive` crate, version v0.8.50
(released 2026-05-31), hosted in the <https://github.com/google/zerocopy>
These source files come from the Rust `zerocopy-derive` crate, version v0.8.54
(released 2026-07-08), hosted in the <https://github.com/google/zerocopy>
repository, licensed under "BSD-2-Clause OR Apache-2.0 OR MIT" and only
modified to add the SPDX license identifiers and to remove the generation of
modified to tweak the SPDX license identifiers and to remove the generation of
non-ASCII identifiers.
For copyright details, please see:
https://github.com/google/zerocopy/blob/v0.8.50/README.md?plain=1
https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-BSD
https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-APACHE
https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-MIT
https://github.com/google/zerocopy/blob/v0.8.54/README.md?plain=1
https://github.com/google/zerocopy/blob/v0.8.54/LICENSE-BSD
https://github.com/google/zerocopy/blob/v0.8.54/LICENSE-APACHE
https://github.com/google/zerocopy/blob/v0.8.54/LICENSE-MIT

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
use proc_macro2::{Span, TokenStream};
use syn::{
parse_quote, Data, DataEnum, DataStruct, DataUnion, Error, Expr, ExprLit, ExprUnary, Lit, UnOp,

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::{Data, DataEnum, DataStruct, DataUnion, Error, Type};

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
use proc_macro2::TokenStream;
use quote::quote;
use syn::{parse_quote, Data, Error, Type};
@ -87,7 +87,6 @@ fn pointer_to_metadata(ptr: *mut Self) -> <Self as #zerocopy_crate::KnownLayout>
};
let inner_extras = {
let leading_fields_tys = leading_fields_tys.clone();
let methods = make_methods(*trailing_field_ty);
let (_, ty_generics, _) = ctx.ast.generics.split_for_impl();

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
pub mod from_bytes;
pub mod into_bytes;
pub mod known_layout;
@ -15,8 +15,8 @@
util::{Ctx, DataExt, FieldBounds, ImplBlockBuilder, Trait},
};
pub(crate) fn derive_immutable(ctx: &Ctx, _top_level: Trait) -> TokenStream {
match &ctx.ast.data {
pub(crate) fn derive_immutable(ctx: &Ctx, _top_level: Trait) -> Result<TokenStream, Error> {
Ok(match &ctx.ast.data {
Data::Struct(strct) => {
ImplBlockBuilder::new(ctx, strct, Trait::Immutable, FieldBounds::ALL_SELF).build()
}
@ -26,7 +26,7 @@ pub(crate) fn derive_immutable(ctx: &Ctx, _top_level: Trait) -> TokenStream {
Data::Union(unn) => {
ImplBlockBuilder::new(ctx, unn, Trait::Immutable, FieldBounds::ALL_SELF).build()
}
}
})
}
pub(crate) fn derive_hash(ctx: &Ctx, _top_level: Trait) -> Result<TokenStream, Error> {
@ -97,16 +97,20 @@ pub(crate) fn derive_split_at(ctx: &Ctx, _top_level: Trait) -> Result<TokenStrea
match &ctx.ast.data {
Data::Struct(_) => {}
Data::Enum(_) | Data::Union(_) => {
return Err(Error::new(Span::call_site(), "can only be applied to structs"));
return ctx
.error_or_skip(Error::new(Span::call_site(), "can only be applied to structs"));
}
};
if repr.get_packed().is_some() {
return Err(Error::new(Span::call_site(), "must not have #[repr(packed)] attribute"));
return ctx.error_or_skip(Error::new(
Span::call_site(),
"must not have #[repr(packed)] attribute",
));
}
if !(repr.is_c() || repr.is_transparent()) {
return Err(Error::new(
return ctx.error_or_skip(Error::new(
Span::call_site(),
"must have #[repr(C)] or #[repr(transparent)] in order to guarantee this type's layout is splitable",
));
@ -116,7 +120,7 @@ pub(crate) fn derive_split_at(ctx: &Ctx, _top_level: Trait) -> Result<TokenStrea
let trailing_field = if let Some(((_, _, trailing_field), _)) = fields.split_last() {
trailing_field
} else {
return Err(Error::new(Span::call_site(), "must at least one field"));
return ctx.error_or_skip(Error::new(Span::call_site(), "must at least one field"));
};
let zerocopy_crate = &ctx.zerocopy_crate;

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
use proc_macro2::TokenStream;
use quote::quote;
use syn::{
@ -531,8 +531,8 @@ fn project(slf: #zerocopy_crate::pointer::PtrInner<'_, Self>) -> *mut <Self as #
data,
Trait::ProjectField {
variant_id: variant_id.clone(),
field: field.clone(),
field_id: field_id.clone(),
field,
field_id,
invariants: parse_quote!((Aliasing, Alignment, #zerocopy_crate::invariant::Initialized)),
},
FieldBounds::None,

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
use proc_macro2::{Span, TokenStream};
use syn::{Data, DataEnum, DataStruct, DataUnion, Error};

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2019 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
@ -129,6 +129,40 @@ fn into_ts(self) -> proc_macro2::TokenStream {
derive!(ByteEq => derive_eq => crate::derive::derive_eq);
derive!(SplitAt => derive_split_at => crate::derive::derive_split_at);
#[cfg_attr(not(zerocopy_unstable_linux), doc(hidden))]
#[proc_macro_derive(most_traits, attributes(zerocopy))]
pub fn most_traits(ts: proc_macro::TokenStream) -> proc_macro::TokenStream {
let ast = syn::parse_macro_input!(ts as DeriveInput);
let ctx = match Ctx::try_from_derive_input(ast) {
Ok(ctx) => ctx,
Err(e) => return e.into_compile_error().into(),
}
.skip_on_error();
// top-level traits for which to attempt a derive
let derives: [(fn(&Ctx, Trait) -> _, _); 6] = [
(crate::derive::known_layout::derive, Trait::KnownLayout),
(crate::derive::derive_immutable, Trait::Immutable),
(crate::derive::from_bytes::derive_from_bytes, Trait::FromBytes),
(crate::derive::into_bytes::derive_into_bytes, Trait::IntoBytes),
(crate::derive::derive_split_at, Trait::SplitAt),
(crate::derive::unaligned::derive_unaligned, Trait::Unaligned),
];
let mut tokens = proc_macro2::TokenStream::new();
for (derive, t) in derives {
tokens.extend(derive(&ctx, t))
}
// We wrap in `const_block` as a backstop in case any derive fails
// to wrap its output in `const_block` (and thus fails to annotate)
// with the full set of `#[allow(...)]` attributes).
let ts = const_block([Some(tokens)]);
#[cfg(test)]
crate::util::testutil::check_hygiene(ts.clone());
ts.into()
}
/// Deprecated: prefer [`FromZeros`] instead.
#[deprecated(since = "0.8.0", note = "`FromZeroes` was renamed to `FromZeros`")]
#[doc(hidden)]

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2019 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2019 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
@ -98,6 +98,11 @@ pub(crate) fn with_input(&self, input: &DeriveInput) -> Self {
}
}
pub(crate) fn skip_on_error(mut self) -> Self {
self.skip_on_error = true;
self
}
pub(crate) fn core_path(&self) -> TokenStream {
let zerocopy_crate = &self.zerocopy_crate;
quote!(#zerocopy_crate::util::macro_util::core_reexport)
@ -106,20 +111,21 @@ pub(crate) fn core_path(&self) -> TokenStream {
pub(crate) fn cfg_compile_error(&self) -> TokenStream {
// By checking both during the compilation of the proc macro *and* in
// the generated code, we ensure that `--cfg
// zerocopy_unstable_derive_on_error` need only be passed *either* when
// zerocopy_unstable_linux` need only be passed *either* when
// compiling this crate *or* when compiling the user's crate. The former
// is preferable, but in some situations (such as when cross-compiling
// using `cargo build --target`), it doesn't get propagated to this
// crate's build by default.
if cfg!(zerocopy_unstable_derive_on_error) {
if cfg!(zerocopy_unstable_linux) {
quote!()
} else if let Some(span) = self.on_error_span {
let core = self.core_path();
let error_message = "`on_error` is experimental; pass '--cfg zerocopy_unstable_derive_on_error' to enable";
let error_message =
"`on_error` is experimental; pass '--cfg zerocopy_unstable_linux' to enable";
quote::quote_spanned! {span=>
#[allow(unused_attributes, unexpected_cfgs)]
const _: () = {
#[cfg(not(zerocopy_unstable_derive_on_error))]
#[cfg(not(zerocopy_unstable_linux))]
#core::compile_error!(#error_message);
};
}
@ -612,6 +618,20 @@ fn bound_tt(ty: &Type, traits: impl Iterator<Item = Trait>, ctx: &Ctx) -> WhereP
}
};
let zerocopy_bounds =
field_type_bounds
.into_iter()
.chain(padding_check_bound)
.chain(self_bounds)
.map(|bound| {
if self.ctx.skip_on_error {
parse_quote!(for<'zc> #bound)
} else {
bound.clone()
}
})
.collect::<Vec<_>>();
let bounds = self
.ctx
.ast
@ -621,9 +641,7 @@ fn bound_tt(ty: &Type, traits: impl Iterator<Item = Trait>, ctx: &Ctx) -> WhereP
.map(|where_clause| where_clause.predicates.iter())
.into_iter()
.flatten()
.chain(field_type_bounds.iter())
.chain(padding_check_bound.iter())
.chain(self_bounds.iter());
.chain(zerocopy_bounds.iter());
// The parameters with trait bounds, but without type defaults.
let mut params: Vec<_> = self

View File

@ -1,14 +1,13 @@
# `zerocopy`
These source files come from the Rust `zerocopy` crate, version v0.8.50
(released 2026-05-31), hosted in the <https://github.com/google/zerocopy>
These source files come from the Rust `zerocopy` crate, version v0.8.54
(released 2026-07-08), hosted in the <https://github.com/google/zerocopy>
repository, licensed under "BSD-2-Clause OR Apache-2.0 OR MIT" and only
modified to add the SPDX license identifiers and to remove `Display`
for `f32` and `f64`.
modified to tweak the SPDX license identifiers.
For copyright details, please see:
https://github.com/google/zerocopy/blob/v0.8.50/README.md?plain=1
https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-BSD
https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-APACHE
https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-MIT
https://github.com/google/zerocopy/blob/v0.8.54/README.md?plain=1
https://github.com/google/zerocopy/blob/v0.8.54/LICENSE-BSD
https://github.com/google/zerocopy/blob/v0.8.54/LICENSE-APACHE
https://github.com/google/zerocopy/blob/v0.8.54/LICENSE-MIT

View File

@ -1,5 +1,4 @@
/* SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT */
/*
Copyright 2026 The Fuchsia Authors

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2024 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2019 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
@ -100,6 +100,7 @@ impl Sealed for super::LittleEndian {}
#[allow(missing_copy_implementations, missing_debug_implementations)]
#[doc(hidden)]
#[derive(PartialEq)]
pub enum Order {
BigEndian,
LittleEndian,
@ -164,6 +165,42 @@ fn fmt(&self, _: &mut Formatter<'_>) -> fmt::Result {
/// A type alias for [`LittleEndian`].
pub type LE = LittleEndian;
macro_rules! impl_dbg_trait {
($name:ident, $native:ident) => {
impl<O: ByteOrder> Debug for $name<O> {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
// This results in a format like "U16(42)".
f.debug_tuple(stringify!($name)).field(&self.get()).finish()
}
}
};
}
macro_rules! impl_dbg_traits {
($name:ident, $native:ident, "floating point number") => {
#[cfg(not(no_fp_fmt_parse))]
impl_dbg_trait!($name, $native);
#[cfg(no_fp_fmt_parse)]
impl<O: ByteOrder> Debug for $name<O> {
#[inline]
fn fmt(&self, _f: &mut Formatter<'_>) -> fmt::Result {
panic!("floating point support is turned off");
}
}
};
($name:ident, $native:ident, "unsigned integer") => {
impl_dbg_traits!($name, $native, @all_types);
};
($name:ident, $native:ident, "signed integer") => {
impl_dbg_traits!($name, $native, @all_types);
};
($name:ident, $native:ident, @all_types) => {
impl_dbg_trait!($name, $native);
};
}
macro_rules! impl_fmt_trait {
($name:ident, $native:ident, $trait:ident) => {
impl<O: ByteOrder> $trait for $name<O> {
@ -177,6 +214,8 @@ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
macro_rules! impl_fmt_traits {
($name:ident, $native:ident, "floating point number") => {
#[cfg(not(no_fp_fmt_parse))]
impl_fmt_trait!($name, $native, Display);
};
($name:ident, $native:ident, "unsigned integer") => {
impl_fmt_traits!($name, $native, @all_types);
@ -687,16 +726,9 @@ fn eq(&self, other: &$native) -> bool {
}
}
impl_dbg_traits!($name, $native, $number_kind);
impl_fmt_traits!($name, $native, $number_kind);
impl_ops_traits!($name, $native, $number_kind);
impl<O: ByteOrder> Debug for $name<O> {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
// This results in a format like "U16(42)".
f.debug_tuple(stringify!($name)).field(&self.get()).finish()
}
}
};
}

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2024 The Fuchsia Authors
//
// Licensed under the 2-Clause BSD License <LICENSE-BSD or

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2024 The Fuchsia Authors
//
// Licensed under the 2-Clause BSD License <LICENSE-BSD or

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2024 The Fuchsia Authors
//
// Licensed under the 2-Clause BSD License <LICENSE-BSD or
@ -1359,7 +1359,7 @@ mod $mod {
#[cfg(not(no_zerocopy_aarch64_simd_1_59_0))]
simd_arch_mod!(
#[cfg(all(
target_arch = "aarch64",
target_arch = "aarch64",
any(
target_endian = "little",
not(no_zerocopy_aarch64_simd_be_1_87_0)

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2024 The Fuchsia Authors
//
// Licensed under the 2-Clause BSD License <LICENSE-BSD or
@ -71,6 +71,8 @@ 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)]
#[cfg_attr(not(zerocopy_inline_always), inline)]
#[cfg_attr(zerocopy_inline_always, inline(always))]
const fn try_to_nonzero_elem_size(&self) -> Option<SizeInfo<NonZeroUsize>> {
Some(match *self {
SizeInfo::Sized { size } => SizeInfo::Sized { size },

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2018 The Fuchsia Authors
//
// Licensed under the 2-Clause BSD License <LICENSE-BSD or
@ -12,7 +12,7 @@
// After updating the following doc comment, make sure to run the following
// command to update `README.md` based on its contents:
//
// cargo -q run --manifest-path tools/Cargo.toml -p generate-readme > README.md
// (cd .. && cargo -q run --manifest-path tools/Cargo.toml -p generate-readme) > README.md
//! ***<span style="font-size: 140%">Fast, safe, <span
//! style="color:red;">compile error</span>. Pick two.</span>***
@ -174,7 +174,7 @@
//!
//! [Miri]: https://github.com/rust-lang/miri
//! [Kani]: https://github.com/model-checking/kani
//! [soundness policy]: https://github.com/google/zerocopy/blob/main/POLICIES.md#soundness
//! [soundness policy]: https://github.com/google/zerocopy/blob/main/zerocopy/POLICIES.md#soundness
//!
//! # Relationship to Project Safe Transmute
//!
@ -203,7 +203,7 @@
//!
//! See our [MSRV policy].
//!
//! [MSRV policy]: https://github.com/google/zerocopy/blob/main/POLICIES.md#msrv
//! [MSRV policy]: https://github.com/google/zerocopy/blob/main/zerocopy/POLICIES.md#msrv
//!
//! # Changelog
//!
@ -435,6 +435,8 @@
WARNING
};
#[cfg(all(any(feature = "derive", test), zerocopy_unstable_linux))]
pub use zerocopy_derive::most_traits;
/// Implements [`KnownLayout`].
///
/// This derive analyzes various aspects of a type's layout that are needed for
@ -2832,7 +2834,7 @@ fn try_ref_from_suffix_with_elems(
/// ```
///
/// [`try_mut_from_bytes`]: TryFromBytes::try_mut_from_bytes
///
///
#[doc = codegen_header!("h5", "try_mut_from_bytes_with_elems")]
///
/// See [`TryFromBytes::try_ref_from_bytes_with_elems`](#method.try_ref_from_bytes_with_elems.codegen).

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2024 The Fuchsia Authors
//
// Licensed under the 2-Clause BSD License <LICENSE-BSD or

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2024 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2024 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2023 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2023 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2025 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2024 The Fuchsia Authors
//
// Licensed under the 2-Clause BSD License <LICENSE-BSD or

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2025 The Fuchsia Authors
//
// Licensed under the 2-Clause BSD License <LICENSE-BSD or

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2022 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2023 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2023 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
@ -150,6 +150,8 @@ pub(crate) fn validate_aligned_to<T: AsAddress, U>(t: T) -> Result<(), Alignment
// Ensures that we add the minimum required padding.
kani::ensures(|&p| p < align.get()),
)]
#[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)]
#[kani::proof_for_contract(padding_needed_for)]
@ -251,6 +253,8 @@ fn proof() {
n & mask
}
#[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() {
b
@ -259,6 +263,8 @@ pub(crate) const fn max(a: NonZeroUsize, b: NonZeroUsize) -> NonZeroUsize {
}
}
#[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() {
b

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
//
// Copyright 2023 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0

View File

@ -206,6 +206,7 @@ static bool is_rust_noreturn(const struct symbol *func)
str_ends_with(func->name, "_4core9panicking18panic_nounwind_fmt") ||
str_ends_with(func->name, "_4core9panicking19assert_failed_inner") ||
str_ends_with(func->name, "_4core9panicking30panic_null_pointer_dereference") ||
str_ends_with(func->name, "_4core9panicking32panic_null_reference_constructed") ||
str_ends_with(func->name, "_4core9panicking36panic_misaligned_pointer_dereference") ||
str_ends_with(func->name, "_7___rustc17rust_begin_unwind") ||
strstr(func->name, "_4core9panicking13assert_failed") ||