Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions zeroize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ pub mod __internal {

/// Auto-deref workaround for deriving `ZeroizeOnDrop`.
pub trait AssertZeroizeOnDrop {
fn zeroize_or_on_drop(&mut self);
fn zeroize_or_on_drop(self);
}

impl<T: ZeroizeOnDrop> AssertZeroizeOnDrop for &mut T {
fn zeroize_or_on_drop(&mut self) {}
fn zeroize_or_on_drop(self) {}
}

/// Auto-deref workaround for deriving `ZeroizeOnDrop`.
Expand Down
15 changes: 15 additions & 0 deletions zeroize/tests/zeroize_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,19 @@ mod custom_derive_tests {

assert_eq!(value.0, 0);
}

#[test]
fn derive_only_zeroize_on_drop() {
#[derive(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])
Comment on lines +246 to +256
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This describes the issue that is not compilable without this fix.

}
}