Skip to content

Commit 26921a3

Browse files
committed
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
1 parent 35556e2 commit 26921a3

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

src/context.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,19 @@ pub trait Signing: Context {}
6969
pub trait Verification: Context {}
7070

7171
/// Represents the set of capabilities needed for signing with a user preallocated memory.
72+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
7273
pub struct SignOnlyPreallocated<'buf> {
7374
phantom: PhantomData<&'buf ()>,
7475
}
7576

7677
/// Represents the set of capabilities needed for verification with a user preallocated memory.
78+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
7779
pub struct VerifyOnlyPreallocated<'buf> {
7880
phantom: PhantomData<&'buf ()>,
7981
}
8082

8183
/// Represents the set of all capabilities with a user preallocated memory.
84+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
8285
pub struct AllPreallocated<'buf> {
8386
phantom: PhantomData<&'buf ()>,
8487
}
@@ -112,14 +115,17 @@ mod alloc_only {
112115

113116
/// Represents the set of capabilities needed for signing.
114117
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
118+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
115119
pub enum SignOnly {}
116120

117121
/// Represents the set of capabilities needed for verification.
118122
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
123+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
119124
pub enum VerifyOnly {}
120125

121126
/// Represents the set of all capabilities.
122127
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
128+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
123129
pub enum All {}
124130

125131
impl Signing for SignOnly {}

src/key.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,8 @@ impl Ord for PublicKey {
511511
}
512512

513513
/// Opaque data structure that holds a keypair consisting of a secret and a public key.
514-
#[derive(Clone)]
514+
// Should secrets implement Copy: https://github.com/rust-bitcoin/rust-secp256k1/issues/363
515+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
515516
pub struct KeyPair(ffi::KeyPair);
516517
impl_display_secret!(KeyPair);
517518

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@
132132
#![deny(non_snake_case)]
133133
#![deny(unused_mut)]
134134
#![warn(missing_docs)]
135+
#![warn(missing_copy_implementations)]
136+
#![warn(missing_debug_implementations)]
135137

136138

137139
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]

src/secret.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ macro_rules! impl_display_secret {
5757
///
5858
/// [`Display`]: fmt::Display
5959
/// [`Debug`]: fmt::Debug
60+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
6061
pub struct DisplaySecret {
6162
secret: [u8; SECRET_KEY_SIZE]
6263
}

0 commit comments

Comments
 (0)