summaryrefslogtreecommitdiffstats
path: root/vendor/zerovec-derive/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/zerovec-derive/src
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/zerovec-derive/src')
-rw-r--r--vendor/zerovec-derive/src/make_ule.rs19
-rw-r--r--vendor/zerovec-derive/src/make_varule.rs15
-rw-r--r--vendor/zerovec-derive/src/utils.rs3
3 files changed, 35 insertions, 2 deletions
diff --git a/vendor/zerovec-derive/src/make_ule.rs b/vendor/zerovec-derive/src/make_ule.rs
index bac31aaae..fb94cbc2c 100644
--- a/vendor/zerovec-derive/src/make_ule.rs
+++ b/vendor/zerovec-derive/src/make_ule.rs
@@ -157,8 +157,8 @@ fn make_ule_enum_impl(
let not_found = not_found.iter().collect::<Vec<_>>();
if !not_found.is_empty() {
- return Error::new(input.span(), &format!("#[make_ule] must be applied to enums with discriminants \
- filling the range from 0 to a maximum; could not find {:?}", not_found))
+ return Error::new(input.span(), format!("#[make_ule] must be applied to enums with discriminants \
+ filling the range from 0 to a maximum; could not find {not_found:?}"))
.to_compile_error();
}
@@ -336,6 +336,19 @@ fn make_ule_struct_impl(
)
};
+ let maybe_hash = if attrs.hash {
+ quote!(
+ #[allow(clippy::derive_hash_xor_eq)]
+ impl core::hash::Hash for #ule_name {
+ fn hash<H>(&self, state: &mut H) where H: core::hash::Hasher {
+ state.write(<#ule_name as zerovec::ule::ULE>::as_byte_slice(&[*self]));
+ }
+ }
+ )
+ } else {
+ quote!()
+ };
+
quote!(
#asule_impl
@@ -344,5 +357,7 @@ fn make_ule_struct_impl(
#derived
#maybe_ord_impls
+
+ #maybe_hash
)
}
diff --git a/vendor/zerovec-derive/src/make_varule.rs b/vendor/zerovec-derive/src/make_varule.rs
index 3220b0f8a..62cf0d9db 100644
--- a/vendor/zerovec-derive/src/make_varule.rs
+++ b/vendor/zerovec-derive/src/make_varule.rs
@@ -233,6 +233,19 @@ pub fn make_varule_impl(attr: AttributeArgs, mut input: DeriveInput) -> TokenStr
quote!()
};
+ let maybe_hash = if attrs.hash {
+ quote!(
+ #[allow(clippy::derive_hash_xor_eq)]
+ impl core::hash::Hash for #ule_name {
+ fn hash<H>(&self, state: &mut H) where H: core::hash::Hasher {
+ state.write(<#ule_name as zerovec::ule::VarULE>::as_byte_slice(&self));
+ }
+ }
+ )
+ } else {
+ quote!()
+ };
+
quote!(
#input
@@ -255,6 +268,8 @@ pub fn make_varule_impl(attr: AttributeArgs, mut input: DeriveInput) -> TokenStr
#maybe_de
#maybe_debug
+
+ #maybe_hash
)
}
diff --git a/vendor/zerovec-derive/src/utils.rs b/vendor/zerovec-derive/src/utils.rs
index 24bb56759..3ebf33bf0 100644
--- a/vendor/zerovec-derive/src/utils.rs
+++ b/vendor/zerovec-derive/src/utils.rs
@@ -212,6 +212,7 @@ pub struct ZeroVecAttrs {
pub serialize: bool,
pub deserialize: bool,
pub debug: bool,
+ pub hash: bool,
}
/// Removes all known zerovec:: attributes from attrs and validates them
@@ -243,6 +244,8 @@ pub fn extract_attributes_common(
attrs.deserialize = true;
} else if ident == "Debug" {
attrs.debug = true;
+ } else if ident == "Hash" {
+ attrs.hash = true;
} else {
return Err(Error::new(
ident.span(),