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: 4 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jobs:
toolchain: nightly
override: true
components: rust-src
- name: Check formatting
env:
DO_FMT: true
run: ./contrib/test.sh
- name: Running address sanitizer
env:
DO_ASAN: true
Expand Down
9 changes: 9 additions & 0 deletions contrib/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ if [ "$DO_ASAN" = true ]; then
cargo run --release --features=alloc --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified alloc Successfully"
fi

# Run formatter if told to.
if [ "$DO_FMT" = true ]; then
if [ "$NIGHTLY" = false ]; then
echo "DO_FMT requires a nightly toolchain (consider using RUSTUP_TOOLCHAIN)"
exit 1
fi
rustup component add rustfmt
cargo fmt --check || exit 1
fi

# Bench if told to, only works with non-stable toolchain (nightly, beta).
if [ "$DO_BENCH" = true ]
Expand Down
3 changes: 3 additions & 0 deletions githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ git diff-index --check --cached $against -- || exit 1

# Check that code lints cleanly.
cargo clippy --features=rand-std,recovery,lowmemory,global-context --all-targets -- -D warnings || exit 1

# Check that there are no formatting issues.
cargo +nightly fmt --check || exit 1
2 changes: 1 addition & 1 deletion src/ecdh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ mod tests {
}

#[cfg(bench)]
#[cfg(feature = "rand-std")] // Currently only a single bench that requires "rand-std".
#[cfg(feature = "rand-std")] // Currently only a single bench that requires "rand-std".
mod benches {
use test::{black_box, Bencher};

Expand Down
2 changes: 1 addition & 1 deletion src/ecdsa/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ mod tests {
}

#[cfg(bench)]
#[cfg(feature = "rand-std")] // Currently only a single bench that requires "rand-std".
#[cfg(feature = "rand-std")] // Currently only a single bench that requires "rand-std".
mod benches {
use test::{black_box, Bencher};

Expand Down
4 changes: 2 additions & 2 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ impl<'a> From<&'a KeyPair> for PublicKey {
impl str::FromStr for KeyPair {
type Err = Error;

#[allow(unused_variables, unreachable_code)] // When built with no default features.
#[allow(unused_variables, unreachable_code)] // When built with no default features.
fn from_str(s: &str) -> Result<Self, Self::Err> {
#[cfg(feature = "global-context")]
let ctx = SECP256K1;
Expand Down Expand Up @@ -1515,7 +1515,7 @@ mod test {
use core::str::FromStr;

#[cfg(feature = "rand")]
use rand::{self, RngCore, rngs::mock::StepRng};
use rand::{self, rngs::mock::StepRng, RngCore};
use serde_test::{Configure, Token};
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as test;
Expand Down
12 changes: 5 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,19 +530,16 @@ pub(crate) fn random_32_bytes<R: rand::Rng + ?Sized>(rng: &mut R) -> [u8; 32] {

#[cfg(test)]
mod tests {
#[allow(unused_imports)] // When building with no default features.
use super::*;

use std::str::FromStr;

#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[allow(unused_imports)] // When building with no default features.
use super::*;
use crate::{constants, ecdsa, from_hex, Error, Message};
#[cfg(feature = "alloc")]
use crate::{ffi, PublicKey, Secp256k1, SecretKey};
use crate::{
constants, ecdsa, from_hex, Error, Message,
};

macro_rules! hex {
($hex:expr) => {{
Expand Down Expand Up @@ -889,9 +886,10 @@ mod tests {
#[test]
#[cfg(feature = "rand-std")]
fn test_hex() {
use super::to_hex;
use rand::RngCore;

use super::to_hex;

let mut rng = rand::thread_rng();
const AMOUNT: usize = 1024;
for i in 0..AMOUNT {
Expand Down
17 changes: 5 additions & 12 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,17 @@
#[macro_export]
macro_rules! impl_array_newtype {
($thing:ident, $ty:ty, $len:expr) => {

// We cannot derive these traits because Rust 1.41.1 requires `std::array::LengthAtMost32`.

impl PartialEq for $thing {
#[inline]
fn eq(&self, other: &$thing) -> bool {
&self[..] == &other[..]
}
fn eq(&self, other: &$thing) -> bool { &self[..] == &other[..] }
}

impl Eq for $thing {}

impl core::hash::Hash for $thing {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
(&self[..]).hash(state)
}
fn hash<H: core::hash::Hasher>(&self, state: &mut H) { (&self[..]).hash(state) }
}

impl PartialOrd for $thing {
Expand All @@ -44,9 +39,7 @@ macro_rules! impl_array_newtype {

impl Ord for $thing {
#[inline]
fn cmp(&self, other: &$thing) -> core::cmp::Ordering {
self[..].cmp(&other[..])
}
fn cmp(&self, other: &$thing) -> core::cmp::Ordering { self[..].cmp(&other[..]) }
}

impl AsRef<[$ty; $len]> for $thing {
Expand Down Expand Up @@ -81,7 +74,7 @@ macro_rules! impl_array_newtype {
dat.as_mut_ptr()
}
}
}
};
}

macro_rules! impl_pretty_debug {
Expand Down Expand Up @@ -139,5 +132,5 @@ macro_rules! impl_fast_comparisons {
self.0.eq_fast_unstable(&other.0)
}
}
}
};
}
4 changes: 3 additions & 1 deletion src/schnorr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::ffi::{self, CPtr};
use crate::key::{KeyPair, XOnlyPublicKey};
#[cfg(feature = "global-context")]
use crate::SECP256K1;
use crate::{constants, from_hex, impl_array_newtype, Error, Message, Secp256k1, Signing, Verification};
use crate::{
constants, from_hex, impl_array_newtype, Error, Message, Secp256k1, Signing, Verification,
};

/// Represents a Schnorr signature.
#[derive(Copy, Clone)]
Expand Down