Skip to content

Commit

Permalink
Merge rust-bitcoin#4049: hashes: Test macros in function scope
Browse files Browse the repository at this point in the history
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
  • Loading branch information
apoelstra committed Feb 17, 2025
2 parents 4712e81 + 8c24395 commit bee652d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions hashes/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FunctionScopeTag>);
}

assert_eq!(2, core::mem::align_of::<FunctionScopeTag>());
assert_eq!(4, core::mem::align_of::<FunctionScopeHash>());
}

// NB: This runs with and without `hex` feature enabled, testing different code paths for each.
#[test]
#[cfg(feature = "alloc")]
Expand Down

0 comments on commit bee652d

Please sign in to comment.