From 26921a31b8a030fba1141aba9ee61201c21b2d6a Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Fri, 7 Jan 2022 10:01:11 +1100 Subject: [PATCH] Add lints to catch missing traits Rustc can warn us when we forget to add `Copy` and `Deubg` trait implementations to types. Add lint directives to enable warnings for missing `Copy` and `Debug` implementations. Use the newly emitted warnings to find types that do not implement our 'standard' traits. These 'standard' traits are defined as the set of attributes that it has been found beneficial to opportunistically add to all types, these are - Copy - Clone - Debug - PartialEq and Eq - PartialOrd and Ord - Hash --- src/context.rs | 6 ++++++ src/key.rs | 3 ++- src/lib.rs | 2 ++ src/secret.rs | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/context.rs b/src/context.rs index 627e016..e617cd5 100644 --- a/src/context.rs +++ b/src/context.rs @@ -69,16 +69,19 @@ pub trait Signing: Context {} pub trait Verification: Context {} /// Represents the set of capabilities needed for signing with a user preallocated memory. +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct SignOnlyPreallocated<'buf> { phantom: PhantomData<&'buf ()>, } /// Represents the set of capabilities needed for verification with a user preallocated memory. +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct VerifyOnlyPreallocated<'buf> { phantom: PhantomData<&'buf ()>, } /// Represents the set of all capabilities with a user preallocated memory. +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct AllPreallocated<'buf> { phantom: PhantomData<&'buf ()>, } @@ -112,14 +115,17 @@ mod alloc_only { /// Represents the set of capabilities needed for signing. #[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))] + #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum SignOnly {} /// Represents the set of capabilities needed for verification. #[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))] + #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum VerifyOnly {} /// Represents the set of all capabilities. #[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))] + #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum All {} impl Signing for SignOnly {} diff --git a/src/key.rs b/src/key.rs index ee52b81..8c0f0a0 100644 --- a/src/key.rs +++ b/src/key.rs @@ -511,7 +511,8 @@ impl Ord for PublicKey { } /// Opaque data structure that holds a keypair consisting of a secret and a public key. -#[derive(Clone)] +// Should secrets implement Copy: https://github.com/rust-bitcoin/rust-secp256k1/issues/363 +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct KeyPair(ffi::KeyPair); impl_display_secret!(KeyPair); diff --git a/src/lib.rs b/src/lib.rs index 4419006..02eb0c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -132,6 +132,8 @@ #![deny(non_snake_case)] #![deny(unused_mut)] #![warn(missing_docs)] +#![warn(missing_copy_implementations)] +#![warn(missing_debug_implementations)] #![cfg_attr(all(not(test), not(feature = "std")), no_std)] diff --git a/src/secret.rs b/src/secret.rs index c174122..28bd80d 100644 --- a/src/secret.rs +++ b/src/secret.rs @@ -57,6 +57,7 @@ macro_rules! impl_display_secret { /// /// [`Display`]: fmt::Display /// [`Debug`]: fmt::Debug +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DisplaySecret { secret: [u8; SECRET_KEY_SIZE] }