From 8c2439550acdf3cb52c78d69eb55160f9d03a139 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 13 Feb 2025 15:02:25 +1100 Subject: [PATCH] hashes: Test macros in function scope The two main public macros can be used in function scope - prove it. While we are at it prove that additional attributes are supported by them both as well as visability keywords. --- hashes/src/macros.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hashes/src/macros.rs b/hashes/src/macros.rs index 12ca01520c..1d35b53f81 100644 --- a/hashes/src/macros.rs +++ b/hashes/src/macros.rs @@ -576,6 +576,25 @@ mod test { fn all_zeros() -> Self { Self::from_byte_array([0; 32]) } } + #[test] + fn macros_work_in_function_scope() { + use crate::sha256t; + + sha256t_tag! { + #[repr(align(2))] // This tests that we can add additional attributes. + pub struct FunctionScopeTag = hash_str("It works"); + } + + hash_newtype! { + /// Some docs. + #[repr(align(4))] // This tests that we can add additional attributes. + pub struct FunctionScopeHash(pub(crate) sha256t::Hash); + } + + assert_eq!(2, core::mem::align_of::()); + assert_eq!(4, core::mem::align_of::()); + } + // NB: This runs with and without `hex` feature enabled, testing different code paths for each. #[test] #[cfg(feature = "alloc")]