diff options
Diffstat (limited to 'library/alloctests/testing/macros.rs')
| -rw-r--r-- | library/alloctests/testing/macros.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/library/alloctests/testing/macros.rs b/library/alloctests/testing/macros.rs index 37cf59bc169..2433e53ca89 100644 --- a/library/alloctests/testing/macros.rs +++ b/library/alloctests/testing/macros.rs @@ -1,8 +1,9 @@ macro_rules! struct_with_counted_drop { - ($struct_name:ident$(($elt_ty:ty))?, $drop_counter:ident $(=> $drop_stmt:expr)?) => { + ($struct_name:ident $(( $( $elt_ty:ty ),+ ))?, $drop_counter:ident $( => $drop_stmt:expr )? ) => { thread_local! {static $drop_counter: ::core::cell::Cell<u32> = ::core::cell::Cell::new(0);} - struct $struct_name$(($elt_ty))?; + #[derive(Clone, Debug, PartialEq)] + struct $struct_name $(( $( $elt_ty ),+ ))?; impl ::std::ops::Drop for $struct_name { fn drop(&mut self) { @@ -12,6 +13,25 @@ macro_rules! struct_with_counted_drop { } } }; + ($struct_name:ident $(( $( $elt_ty:ty ),+ ))?, $drop_counter:ident[ $drop_key:expr,$key_ty:ty ] $( => $drop_stmt:expr )? ) => { + thread_local! { + static $drop_counter: ::core::cell::RefCell<::std::collections::HashMap<$key_ty, u32>> = + ::core::cell::RefCell::new(::std::collections::HashMap::new()); + } + + #[derive(Clone, Debug, PartialEq)] + struct $struct_name $(( $( $elt_ty ),+ ))?; + + impl ::std::ops::Drop for $struct_name { + fn drop(&mut self) { + $drop_counter.with_borrow_mut(|counter| { + *counter.entry($drop_key(self)).or_default() += 1; + }); + + $($drop_stmt(self))? + } + } + }; } pub(crate) use struct_with_counted_drop; |
