From 5b86e38aea14f5f2881bfd2c12f0446a5b38ffec Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 28 Jun 2022 13:07:08 +1000 Subject: [PATCH 1/2] Put compiler attributes below rustdocs It is conventional, at least within the `rust-bitcoin` organisation to put compiler attributes _below_ the associated rustdocs. --- secp256k1-sys/src/macros.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/secp256k1-sys/src/macros.rs b/secp256k1-sys/src/macros.rs index 10d715e..1089e79 100644 --- a/secp256k1-sys/src/macros.rs +++ b/secp256k1-sys/src/macros.rs @@ -20,26 +20,26 @@ macro_rules! impl_array_newtype { impl Copy for $thing {} impl $thing { - #[inline] /// Converts the object to a raw pointer for FFI interfacing + #[inline] pub fn as_ptr(&self) -> *const $ty { let &$thing(ref dat) = self; dat.as_ptr() } - #[inline] /// Converts the object to a mutable raw pointer for FFI interfacing + #[inline] pub fn as_mut_ptr(&mut self) -> *mut $ty { let &mut $thing(ref mut dat) = self; dat.as_mut_ptr() } - #[inline] /// Returns the length of the object as an array + #[inline] pub fn len(&self) -> usize { $len } - #[inline] /// Returns whether the object as an array is empty + #[inline] pub fn is_empty(&self) -> bool { false } } From 56f18430ffb362330537ca9991c62802af4d4ad9 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 28 Jun 2022 13:18:57 +1000 Subject: [PATCH 2/2] Add must_use for mut self key manipulation methods We recently added a bunch of key tweaking methods that take `mut self` and return the tweaked/negated keys. These functions are pure and as such the returned result is expected to be used. To help downstream users use the API correctly add `must_use` attributes with a descriptive error string for each of the methods that takes `mut self`. --- src/key.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/key.rs b/src/key.rs index b862f19..8858ede 100644 --- a/src/key.rs +++ b/src/key.rs @@ -243,6 +243,7 @@ impl SecretKey { /// Negates the secret key. #[inline] + #[must_use = "you forgot to use the negated secret key"] pub fn negate(mut self) -> SecretKey { unsafe { let res = ffi::secp256k1_ec_seckey_negate( @@ -272,6 +273,7 @@ impl SecretKey { /// /// Returns an error if the resulting key would be invalid. #[inline] + #[must_use = "you forgot to use the tweaked secret key"] pub fn add_tweak(mut self, tweak: &Scalar) -> Result { unsafe { if ffi::secp256k1_ec_seckey_tweak_add( @@ -302,6 +304,7 @@ impl SecretKey { /// /// Returns an error if the resulting key would be invalid. #[inline] + #[must_use = "you forgot to use the tweaked secret key"] pub fn mul_tweak(mut self, tweak: &Scalar) -> Result { unsafe { if ffi::secp256k1_ec_seckey_tweak_mul( @@ -536,6 +539,7 @@ impl PublicKey { /// Negates the public key. #[inline] + #[must_use = "you forgot to use the negated public key"] pub fn negate(mut self, secp: &Secp256k1) -> PublicKey { unsafe { let res = ffi::secp256k1_ec_pubkey_negate(secp.ctx, &mut self.0); @@ -566,6 +570,7 @@ impl PublicKey { /// /// Returns an error if the resulting key would be invalid. #[inline] + #[must_use = "you forgot to use the tweaked public key"] pub fn add_exp_tweak( mut self, secp: &Secp256k1, @@ -602,6 +607,7 @@ impl PublicKey { /// /// Returns an error if the resulting key would be invalid. #[inline] + #[must_use = "you forgot to use the tweaked public key"] pub fn mul_tweak( mut self, secp: &Secp256k1, @@ -971,6 +977,7 @@ impl KeyPair { /// ``` // TODO: Add checked implementation #[inline] + #[must_use = "you forgot to use the tweaked key pair"] pub fn add_xonly_tweak( mut self, secp: &Secp256k1, @@ -1270,6 +1277,7 @@ impl XOnlyPublicKey { /// let tweaked = xonly.add_tweak(&secp, &tweak).expect("Improbable to fail with a randomly generated tweak"); /// # } /// ``` + #[must_use = "you forgot to use the tweaked xonly pubkey"] pub fn add_tweak( mut self, secp: &Secp256k1,