Skip to content

Commit bee652d

Browse files
committed
Merge rust-bitcoin#4049: hashes: Test macros in function scope
8c24395 hashes: Test macros in function scope (Tobin C. Harding) Pull request description: 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. ACKs for top commit: apoelstra: ACK 8c24395; successfully ran local tests Kixunil: ACK 8c24395 Tree-SHA512: 66d6a9fd142966f6e68e9a5cb849345a77357dc6e415a10507418425a4cf6a1440deaf47515db43b9ec5b5d337d53164c617db165cb2ff782cf6a6e4ff195c77
2 parents 4712e81 + 8c24395 commit bee652d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

hashes/src/macros.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,25 @@ mod test {
576576
fn all_zeros() -> Self { Self::from_byte_array([0; 32]) }
577577
}
578578

579+
#[test]
580+
fn macros_work_in_function_scope() {
581+
use crate::sha256t;
582+
583+
sha256t_tag! {
584+
#[repr(align(2))] // This tests that we can add additional attributes.
585+
pub struct FunctionScopeTag = hash_str("It works");
586+
}
587+
588+
hash_newtype! {
589+
/// Some docs.
590+
#[repr(align(4))] // This tests that we can add additional attributes.
591+
pub struct FunctionScopeHash(pub(crate) sha256t::Hash<FunctionScopeTag>);
592+
}
593+
594+
assert_eq!(2, core::mem::align_of::<FunctionScopeTag>());
595+
assert_eq!(4, core::mem::align_of::<FunctionScopeHash>());
596+
}
597+
579598
// NB: This runs with and without `hex` feature enabled, testing different code paths for each.
580599
#[test]
581600
#[cfg(feature = "alloc")]

0 commit comments

Comments
 (0)