From f67081a01c5e11138389087d18eb5214d46a5f25 Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Tue, 22 Dec 2020 11:24:11 +1100 Subject: [PATCH 1/4] Allow unnecessary parentheses Clippy emits: warning: unnecessary parentheses around assigned value Add a attribute to allow unnecessary parentheses. --- secp256k1-sys/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/secp256k1-sys/src/lib.rs b/secp256k1-sys/src/lib.rs index 170d18b..0db8581 100644 --- a/secp256k1-sys/src/lib.rs +++ b/secp256k1-sys/src/lib.rs @@ -43,6 +43,7 @@ pub const SECP256K1_START_VERIFY: c_uint = 1 | (1 << 8); /// Flag for context to enable signing precomputation pub const SECP256K1_START_SIGN: c_uint = 1 | (1 << 9); /// Flag for keys to indicate uncompressed serialization format +#[allow(unused_parens)] pub const SECP256K1_SER_UNCOMPRESSED: c_uint = (1 << 1); /// Flag for keys to indicate compressed serialization format pub const SECP256K1_SER_COMPRESSED: c_uint = (1 << 1) | (1 << 8); From 617bff9df3ef852cd5bfb837509a8db716f4a31c Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Tue, 22 Dec 2020 11:26:43 +1100 Subject: [PATCH 2/4] Conditionally include ALIGN_TO This const is only used under specific features, use `cfg` to conditionally build it in. Removes clippy warning. --- secp256k1-sys/src/types.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/secp256k1-sys/src/types.rs b/secp256k1-sys/src/types.rs index 98b35ef..0b18ced 100644 --- a/secp256k1-sys/src/types.rs +++ b/secp256k1-sys/src/types.rs @@ -40,6 +40,7 @@ impl AlignedType { } } +#[cfg(all(feature = "std", not(feature = "external-symbols")))] pub(crate) const ALIGN_TO: usize = mem::align_of::(); From 3afc172096c9a2f21c90502264bf60207009f8bc Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Tue, 22 Dec 2020 11:28:57 +1100 Subject: [PATCH 3/4] Conditionally compile fn strlen `strlen` is only used under certain feature flags, use `cfg` to conditionally build it in. Clears clippy warning. --- secp256k1-sys/src/lib.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/secp256k1-sys/src/lib.rs b/secp256k1-sys/src/lib.rs index 0db8581..3b5a7bf 100644 --- a/secp256k1-sys/src/lib.rs +++ b/secp256k1-sys/src/lib.rs @@ -630,7 +630,8 @@ pub unsafe extern "C" fn rustsecp256k1_v0_3_1_default_error_callback_fn(message: panic!("[libsecp256k1] internal consistency check failed {}", msg); } - +#[no_mangle] +#[cfg(not(feature = "external-symbols"))] unsafe fn strlen(mut str_ptr: *const c_char) -> usize { let mut ctr = 0; while *str_ptr != '\0' as c_char { @@ -1161,11 +1162,13 @@ pub use self::fuzz_dummy::*; #[cfg(test)] mod tests { - use std::ffi::CString; - use super::strlen; - + #[no_mangle] + #[cfg(not(feature = "external-symbols"))] #[test] fn test_strlen() { + use std::ffi::CString; + use super::strlen; + let orig = "test strlen \t \n"; let test = CString::new(orig).unwrap(); From 02dec3eb9b0d79fa570800f29968492a7d71242f Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Tue, 22 Dec 2020 11:47:22 +1100 Subject: [PATCH 4/4] Implement AsRef instead of custom method Clippy emits a warning since we define a method that has the same name as a standard trait. Implement the trait `AsRef` instead of using a custom method. --- secp256k1-sys/src/macros.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/secp256k1-sys/src/macros.rs b/secp256k1-sys/src/macros.rs index 4a30c27..5ca0198 100644 --- a/secp256k1-sys/src/macros.rs +++ b/secp256k1-sys/src/macros.rs @@ -34,13 +34,6 @@ macro_rules! impl_array_newtype { dat.as_mut_ptr() } - #[inline] - /// Gets a reference to the underlying array - pub fn as_ref(&self) -> &[$ty; $len] { - let &$thing(ref dat) = self; - dat - } - #[inline] /// Returns the length of the object as an array pub fn len(&self) -> usize { $len } @@ -50,6 +43,15 @@ macro_rules! impl_array_newtype { pub fn is_empty(&self) -> bool { false } } + impl AsRef<[$ty; $len]> for $thing { + #[inline] + /// Gets a reference to the underlying array + fn as_ref(&self) -> &[$ty; $len] { + let &$thing(ref dat) = self; + dat + } + } + impl PartialEq for $thing { #[inline] fn eq(&self, other: &$thing) -> bool {