From ba4e7e732dea2c9adaf6fa4803362cd9a2b1adfe Mon Sep 17 00:00:00 2001 From: daxpedda Date: Mon, 31 Jan 2022 16:04:57 +0100 Subject: [PATCH] Fix ambiguous method for `AssertZeroizeOnDrop` (#725) --- zeroize/src/lib.rs | 2 +- zeroize/tests/zeroize_derive.rs | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/zeroize/src/lib.rs b/zeroize/src/lib.rs index 7890d8f8..3f1fd1f9 100644 --- a/zeroize/src/lib.rs +++ b/zeroize/src/lib.rs @@ -271,7 +271,7 @@ pub mod __internal { fn zeroize_or_on_drop(self); } - impl AssertZeroizeOnDrop for &mut T { + impl AssertZeroizeOnDrop for &&mut T { fn zeroize_or_on_drop(self) {} } diff --git a/zeroize/tests/zeroize_derive.rs b/zeroize/tests/zeroize_derive.rs index 1e9e12ac..9775ab06 100644 --- a/zeroize/tests/zeroize_derive.rs +++ b/zeroize/tests/zeroize_derive.rs @@ -242,7 +242,7 @@ mod custom_derive_tests { } #[test] - fn derive_only_zeroize_on_drop() { + fn derive_inherit_zeroize_on_drop() { #[derive(ZeroizeOnDrop)] struct X([u8; 3]); @@ -255,4 +255,34 @@ mod custom_derive_tests { } assert_eq!(&value.0 .0, &[0, 0, 0]) } + + #[test] + fn derive_inherit_from_both() { + #[derive(Zeroize, ZeroizeOnDrop)] + struct X([u8; 3]); + + #[derive(ZeroizeOnDrop)] + struct Z(X); + + let mut value = Z(X([1, 2, 3])); + unsafe { + std::ptr::drop_in_place(&mut value); + } + assert_eq!(&value.0 .0, &[0, 0, 0]) + } + + #[test] + fn derive_inherit_both() { + #[derive(Zeroize, ZeroizeOnDrop)] + struct X([u8; 3]); + + #[derive(Zeroize, ZeroizeOnDrop)] + struct Z(X); + + let mut value = Z(X([1, 2, 3])); + unsafe { + std::ptr::drop_in_place(&mut value); + } + assert_eq!(&value.0 .0, &[0, 0, 0]) + } }