Skip to content

Commit 3afd11d

Browse files
committed
Merge rust-bitcoin/rust-bitcoin#1079: Run clippy from the test script
74f3a5a Run clippy from the test script (Tobin C. Harding) aa8109a Use struct field short form (Tobin C. Harding) d1a0540 Remove redundant calls to clone (Tobin C. Harding) 1964925 Use assert instead of assert_eq (Tobin C. Harding) 3173ef9 Remove unnecessary explicit reference (Tobin C. Harding) Pull request description: Currently we run clippy in CI using a github action. The invocation has a couple of shortcomings 1. it does not lint the tests (this requires `--all-targets`) 2. it does not lint the examples I could not find a way to lint the examples without explicitly linting each example by name. **This PR does the following:** - Fix clippy issues (patch 1-4) - Move the clippy control to `test.sh` - Add an env var `DO_LINT` to control it - Remove the separate CI job - Run the linter during the `Test` job using the stable toolchain. - Run clippy with ` --all-features` AND `--all-targets` (only recently made possible). - Run each example explicitly Thanks to dunxen for noticing all the errors in my psbt example on review and prompting me to work out why clippy was not running :) ACKs for top commit: apoelstra: ACK 74f3a5a Kixunil: ACK 74f3a5a Tree-SHA512: 56dc6262144f4caa5efa6fdc46aeecf7bddc050ef134a639b31a34d4c5e01abcdeda18a00f4ded443866bbdfc982b4e5b67b0089639e0c253e207f0b54777f57
2 parents e33be0f + 30a6dc9 commit 3afd11d

File tree

6 files changed

+18
-25
lines changed

6 files changed

+18
-25
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
- rust: stable
1414
env:
1515
DO_COV: true
16+
DO_LINT: true
1617
AS_DEPENDENCY: true
1718
DO_NO_STD: true
1819
- rust: beta
@@ -106,19 +107,3 @@ jobs:
106107
RUSTFLAGS: "-C link-arg=-Tlink.x"
107108
CARGO_TARGET_THUMBV7M_NONE_EABI_RUNNER: "qemu-system-arm -cpu cortex-m3 -machine mps2-an385 -nographic -semihosting-config enable=on,target=native -kernel"
108109
run: cd embedded && cargo run --target thumbv7m-none-eabi
109-
110-
Clippy:
111-
name: Clippy
112-
runs-on: ubuntu-latest
113-
steps:
114-
- uses: actions/checkout@v2
115-
- uses: actions-rs/toolchain@v1
116-
with:
117-
profile: minimal
118-
toolchain: stable
119-
override: true
120-
- run: rustup component add clippy
121-
- uses: actions-rs/cargo@v1
122-
with:
123-
command: clippy
124-
args: --all-features -- -D warnings

contrib/test.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ if [ "$duplicate_dependencies" -ne 0 ]; then
3131
exit 1
3232
fi
3333

34+
if [ "$DO_LINT" = true ]
35+
then
36+
cargo clippy --all-features --all-targets -- -D warnings
37+
cargo clippy --example bip32 -- -D warnings
38+
cargo clippy --example handshake -- -D warnings
39+
cargo clippy --example ecdsa-psbt --features=bitcoinconsensus -- -D warnings
40+
fi
41+
3442
echo "********* Testing std *************"
3543
# Test without any features other than std first
3644
cargo test --verbose --no-default-features --features="std"

src/util/amount.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,10 +2033,10 @@ mod tests {
20332033

20342034
let json = "{\"amt\": 21000000.00000001, \
20352035
\"samt\": -21000000.00000001}";
2036-
let t: T = serde_json::from_str(&json).unwrap();
2036+
let t: T = serde_json::from_str(json).unwrap();
20372037
assert_eq!(t, orig);
20382038

2039-
let value: serde_json::Value = serde_json::from_str(&json).unwrap();
2039+
let value: serde_json::Value = serde_json::from_str(json).unwrap();
20402040
assert_eq!(t, serde_json::from_value(value).unwrap());
20412041

20422042
// errors

src/util/key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ mod tests {
638638
];
639639

640640
let s = Secp256k1::new();
641-
let sk = PrivateKey::from_str(&KEY_WIF).unwrap();
641+
let sk = PrivateKey::from_str(KEY_WIF).unwrap();
642642
let pk = PublicKey::from_private_key(&s, &sk);
643643
let pk_u = PublicKey {
644644
inner: pk.inner,

src/util/misc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ mod tests {
317317

318318
let secp = secp256k1::Secp256k1::new();
319319
let message = "rust-bitcoin MessageSignature test";
320-
let msg_hash = super::signed_msg_hash(&message);
320+
let msg_hash = super::signed_msg_hash(message);
321321
let msg = secp256k1::Message::from(msg_hash);
322322

323323

@@ -331,7 +331,7 @@ mod tests {
331331
assert_eq!(signature.to_base64(), signature.to_string());
332332
let signature2 = super::MessageSignature::from_str(&signature.to_string()).unwrap();
333333
let pubkey = signature2.recover_pubkey(&secp, msg_hash).unwrap();
334-
assert_eq!(pubkey.compressed, true);
334+
assert!(pubkey.compressed);
335335
assert_eq!(pubkey.inner, secp256k1::PublicKey::from_secret_key(&secp, &privkey));
336336

337337
let p2pkh = Address::p2pkh(&pubkey, Network::Bitcoin);
@@ -357,7 +357,7 @@ mod tests {
357357

358358
let secp = secp256k1::Secp256k1::new();
359359
let message = "a different message from what was signed";
360-
let msg_hash = super::signed_msg_hash(&message);
360+
let msg_hash = super::signed_msg_hash(message);
361361

362362
// Signature of msg = "rust-bitcoin MessageSignature test"
363363
// Signed with pk "UuOGDsfLPr4HIMKQX0ipjJeRaj1geCq3yPUF2COP5ME="

src/util/psbt/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ mod tests {
543543
let xpub: ExtendedPubKey =
544544
"xpub661MyMwAqRbcGoRVtwfvzZsq2VBJR1LAHfQstHUoxqDorV89vRoMxUZ27kLrraAj6MPi\
545545
QfrDb27gigC1VS1dBXi5jGpxmMeBXEkKkcXUTg4".parse().unwrap();
546-
vec![(xpub, key_source.clone())].into_iter().collect()
546+
vec![(xpub, key_source)].into_iter().collect()
547547
},
548548
unsigned_tx: {
549549
let mut unsigned = tx.clone();
@@ -579,8 +579,8 @@ mod tests {
579579
}],
580580
outputs: vec![Output {
581581
bip32_derivation: keypaths,
582-
proprietary: proprietary.clone(),
583-
unknown: unknown.clone(),
582+
proprietary,
583+
unknown,
584584
..Default::default()
585585
}],
586586
};

0 commit comments

Comments
 (0)