Skip to content

Commit b4758ad

Browse files
committed
Merge #295: ci: fix clippy lints and a couple other small things
48634a8 clippy: enable lossless-cast lint (Andrew Poelstra) 1b43322 clippy: address all current lints (Andrew Poelstra) 1a3cc54 ci: improve compiler versioning (Andrew Poelstra) Pull request description: * Fix clippy lints * Enable a few more lints related to casting * Fix CI to use the `nightly-version` version of clippy so that we won't break as new lints come out ACKs for top commit: canndrew: ACK 48634a8 Tree-SHA512: b1df3d9afa13eb239acd5ed791c8128196f857a7907127852d783dee65db3ccd86773cabc5eaff3e2a56932888976ebf244a128ebb80845729560febae6c4662
2 parents 236ca7a + 48634a8 commit b4758ad

File tree

7 files changed

+56
-15
lines changed

7 files changed

+56
-15
lines changed

.github/workflows/main.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,22 @@ jobs:
77
runs-on: ubuntu-24.04
88
outputs:
99
nightly_version: ${{ steps.read_toolchain.outputs.nightly_version }}
10+
msrv_version: ${{ steps.read_msrv.outputs.msrv_version }}
1011
steps:
1112
- name: "Checkout repo"
1213
uses: actions/checkout@v4
1314
- name: "Read nightly version"
1415
id: read_toolchain
15-
run: echo "nightly_version=$(cat nightly-version)" >> $GITHUB_OUTPUT
16+
run: |
17+
set -euo pipefail
18+
version=$(cat nightly-version)
19+
echo "nightly_version=$version" >> $GITHUB_OUTPUT
20+
- name: Read MSRV from clippy.toml
21+
id: read_msrv
22+
run: |
23+
set -euo pipefail
24+
msrv=$(grep '^msrv *= *"' clippy.toml | sed -E 's/.*"([^"]+)".*/\1/')
25+
echo "msrv_version=$msrv" >> "$GITHUB_OUTPUT"
1626
1727
fmt:
1828
name: Rustfmt
@@ -66,7 +76,7 @@ jobs:
6676
- stable
6777
- beta
6878
- ${{ needs.Prepare.outputs.nightly_version }}
69-
- 1.78.0
79+
- ${{ needs.Prepare.outputs.msrv_version }}
7080
steps:
7181
- name: Checkout Crate
7282
uses: actions/checkout@v4
@@ -100,6 +110,7 @@ jobs:
100110

101111
clippy:
102112
name: Clippy
113+
needs: Prepare
103114
runs-on: ${{ matrix.os }}
104115
strategy:
105116
matrix:
@@ -110,6 +121,7 @@ jobs:
110121
- name: Checkout Toolchain
111122
uses: dtolnay/rust-toolchain@stable
112123
with:
124+
toolchain: ${{ needs.Prepare.outputs.nightly_version }}
113125
components: clippy
114126
- name: Running cargo clippy
115127
run: cargo clippy --workspace --all-targets -- --deny warnings

Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,21 @@ exclude = ["jets-bench"]
4747

4848
[lints.rust]
4949
unexpected_cfgs = { level = "deny", check-cfg = ['cfg(bench)'] }
50+
51+
[lints.clippy]
52+
# Exclude lints we don't think are valuable.
53+
needless_question_mark = "allow" # https://github.com/rust-bitcoin/rust-bitcoin/pull/2134
54+
manual_range_contains = "allow" # More readable than clippy's format.
55+
uninlined_format_args = "allow" # This is a subjective style choice.
56+
float_cmp = "allow" # Bitcoin floats are typically limited to 8 decimal places and we want them exact.
57+
match_bool = "allow" # Adds extra indentation and LOC.
58+
match_same_arms = "allow" # Collapses things that are conceptually unrelated to each other.
59+
must_use_candidate = "allow" # Useful for audit but many false positives.
60+
similar_names = "allow" # Too many (subjectively) false positives.
61+
# Cast-related lints
62+
cast_lossless = "warn"
63+
cast_possible_truncation = "allow" # All casts should include a code comment (except test code).
64+
cast_possible_wrap = "allow" # Same as above re code comment.
65+
cast_precision_loss = "warn"
66+
cast_ptr_alignment = "warn"
67+
cast_sign_loss = "allow" # All casts should include a code comment (except in test code).

simplicity-sys/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,14 @@ test-utils = []
2020

2121
[lints.rust]
2222
unexpected_cfgs = { level = "deny", check-cfg = ['cfg(fuzzing)'] }
23+
24+
[lints.clippy]
25+
# Exclude lints we don't think are valuable.
26+
needless_question_mark = "allow" # https://github.com/rust-bitcoin/rust-bitcoin/pull/2134
27+
manual_range_contains = "allow" # More readable than clippy's format.
28+
uninlined_format_args = "allow" # This is a subjective style choice.
29+
float_cmp = "allow" # Bitcoin floats are typically limited to 8 decimal places and we want them exact.
30+
match_bool = "allow" # Adds extra indentation and LOC.
31+
match_same_arms = "allow" # Collapses things that are conceptually unrelated to each other.
32+
must_use_candidate = "allow" # Useful for audit but many false positives.
33+
similar_names = "allow" # Too many (subjectively) false positives.

src/node/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ impl<N: Marker> Node<N> {
703703
///
704704
/// The linear string has no sharing and may be **exponentially larger**
705705
/// than the originally shared expression!
706-
pub fn display_expr(&self) -> DisplayExpr<N> {
706+
pub fn display_expr(&self) -> DisplayExpr<'_, N> {
707707
DisplayExpr::from(self)
708708
}
709709
}

src/policy/satisfy.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ mod tests {
312312

313313
fn get_satisfier(
314314
env: &ElementsEnv<Arc<elements::Transaction>>,
315-
) -> PolicySatisfier<XOnlyPublicKey> {
315+
) -> PolicySatisfier<'_, XOnlyPublicKey> {
316316
let mut preimages = HashMap::new();
317317

318318
for i in 0..3 {
@@ -555,14 +555,14 @@ mod tests {
555555
let witness = to_witness(&program);
556556
assert_eq!(2, witness.len());
557557

558-
assert_eq!(Value::u1(bit as u8), *witness[0]);
558+
assert_eq!(Value::u1(u8::from(bit)), *witness[0]);
559559
let preimage_bytes = witness[1]
560560
.iter_padded()
561561
.try_collect_bytes()
562562
.expect("to bytes");
563563
let witness_preimage =
564564
Preimage32::try_from(preimage_bytes.as_slice()).expect("to array");
565-
assert_eq!(preimages[bit as usize], witness_preimage);
565+
assert_eq!(preimages[usize::from(bit)], witness_preimage);
566566

567567
execute_successful(program, &env);
568568
};
@@ -663,7 +663,7 @@ mod tests {
663663
],
664664
);
665665

666-
match bit0 as u8 + bit1 as u8 + bit2 as u8 {
666+
match u8::from(bit0) + u8::from(bit1) + u8::from(bit2) {
667667
3 => assert_branches(&policy, &[bit0, bit1, false]),
668668
2 => assert_branches(&policy, &[bit0, bit1, bit2]),
669669
_ => assert!(policy.satisfy(&satisfier, &env).is_err()),

src/types/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl Context {
231231
}
232232

233233
/// Locks the underlying slab mutex.
234-
fn lock(&self) -> LockedContext {
234+
fn lock(&self) -> LockedContext<'_> {
235235
LockedContext {
236236
context: Arc::as_ptr(&self.slab),
237237
slab: self.slab.lock().unwrap(),

src/value.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ impl Value {
435435
}
436436

437437
/// A reference to this value, which can be recursed over.
438-
pub fn as_ref(&self) -> ValueRef {
438+
pub fn as_ref(&self) -> ValueRef<'_> {
439439
ValueRef {
440440
inner: &self.inner,
441441
bit_offset: self.bit_offset,
@@ -444,17 +444,17 @@ impl Value {
444444
}
445445

446446
/// Access the inner value of a left sum value.
447-
pub fn as_left(&self) -> Option<ValueRef> {
447+
pub fn as_left(&self) -> Option<ValueRef<'_>> {
448448
self.as_ref().as_left()
449449
}
450450

451451
/// Access the inner value of a right sum value.
452-
pub fn as_right(&self) -> Option<ValueRef> {
452+
pub fn as_right(&self) -> Option<ValueRef<'_>> {
453453
self.as_ref().as_right()
454454
}
455455

456456
/// Access the inner values of a product value.
457-
pub fn as_product(&self) -> Option<(ValueRef, ValueRef)> {
457+
pub fn as_product(&self) -> Option<(ValueRef<'_>, ValueRef<'_>)> {
458458
self.as_ref().as_product()
459459
}
460460

@@ -590,7 +590,7 @@ impl Value {
590590
/// The returned bytes match the padded bit-encoding of the value. You
591591
/// may wish to call [`Self::iter_padded`] instead to obtain the bits,
592592
/// but this method is more efficient in some contexts.
593-
pub fn raw_byte_iter(&self) -> RawByteIter {
593+
pub fn raw_byte_iter(&self) -> RawByteIter<'_> {
594594
RawByteIter {
595595
value: self,
596596
yielded_bytes: 0,
@@ -600,14 +600,14 @@ impl Value {
600600
/// Return an iterator over the compact bit encoding of the value.
601601
///
602602
/// This encoding is used for writing witness data and for computing IHRs.
603-
pub fn iter_compact(&self) -> CompactBitsIter {
603+
pub fn iter_compact(&self) -> CompactBitsIter<'_> {
604604
CompactBitsIter::new(self.as_ref())
605605
}
606606

607607
/// Return an iterator over the padded bit encoding of the value.
608608
///
609609
/// This encoding is used to represent the value in the Bit Machine.
610-
pub fn iter_padded(&self) -> PreOrderIter {
610+
pub fn iter_padded(&self) -> PreOrderIter<'_> {
611611
PreOrderIter {
612612
inner: BitIter::new(self.raw_byte_iter()).take(self.ty.bit_width()),
613613
}

0 commit comments

Comments
 (0)