Skip to content

Commit 58db4c4

Browse files
authored
Merge pull request #228 from apoelstra/2025-06_clippy
Enable a ton of pedantic clippy lints
2 parents 378e753 + 57c81d3 commit 58db4c4

38 files changed

+887
-761
lines changed

.github/workflows/rust.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ jobs:
4949
run: ./contrib/test.sh
5050

5151
MSRV:
52-
name: Test - 1.56.1 toolchain
52+
name: Test - 1.63.0 toolchain
5353
runs-on: ubuntu-latest
5454
strategy:
5555
fail-fast: false
5656
steps:
5757
- name: Checkout Crate
5858
uses: actions/checkout@v3
5959
- name: Checkout Toolchain
60-
uses: dtolnay/rust-toolchain@1.56.1
60+
uses: dtolnay/rust-toolchain@1.63.0
6161
- name: Running test script
6262
env:
6363
DO_DOCS: false

Cargo.toml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,129 @@ name = "tx"
5757
[workspace]
5858
members = ["elementsd-tests"]
5959
exclude = ["fuzz"]
60+
61+
[lints.clippy]
62+
# Exclude lints we don't think are valuable.
63+
needless_question_mark = "allow" # https://github.com/rust-bitcoin/rust-bitcoin/pull/2134
64+
manual_range_contains = "allow" # More readable than clippy's format.
65+
uninlined_format_args = "allow" # This is a subjective style choice.
66+
float_cmp = "allow" # Bitcoin floats are typically limited to 8 decimal places and we want them exact.
67+
match_bool = "allow" # Adds extra indentation and LOC.
68+
match_same_arms = "allow" # Collapses things that are conceptually unrelated to each other.
69+
must_use_candidate = "allow" # Useful for audit but many false positives.
70+
similar_names = "allow" # Too many (subjectively) false positives.
71+
# Exhaustive list of pedantic clippy lints
72+
assigning_clones = "warn"
73+
bool_to_int_with_if = "warn"
74+
borrow_as_ptr = "warn"
75+
case_sensitive_file_extension_comparisons = "warn"
76+
cast_lossless = "warn"
77+
cast_possible_truncation = "allow" # All casts should include a code comment (except test code).
78+
cast_possible_wrap = "allow" # Same as above re code comment.
79+
cast_precision_loss = "warn"
80+
cast_ptr_alignment = "warn"
81+
cast_sign_loss = "allow" # All casts should include a code comment (except in test code).
82+
checked_conversions = "warn"
83+
cloned_instead_of_copied = "warn"
84+
copy_iterator = "warn"
85+
default_trait_access = "warn"
86+
doc_link_with_quotes = "warn"
87+
doc_markdown = "warn"
88+
empty_enum = "warn"
89+
enum_glob_use = "warn"
90+
expl_impl_clone_on_copy = "warn"
91+
explicit_deref_methods = "warn"
92+
explicit_into_iter_loop = "warn"
93+
explicit_iter_loop = "warn"
94+
filter_map_next = "warn"
95+
flat_map_option = "warn"
96+
fn_params_excessive_bools = "warn"
97+
from_iter_instead_of_collect = "warn"
98+
if_not_else = "warn"
99+
ignored_unit_patterns = "warn"
100+
implicit_clone = "warn"
101+
implicit_hasher = "warn"
102+
inconsistent_struct_constructor = "warn"
103+
index_refutable_slice = "warn"
104+
inefficient_to_string = "warn"
105+
inline_always = "warn"
106+
into_iter_without_iter = "warn"
107+
invalid_upcast_comparisons = "warn"
108+
items_after_statements = "warn"
109+
iter_filter_is_ok = "warn"
110+
iter_filter_is_some = "warn"
111+
iter_not_returning_iterator = "warn"
112+
iter_without_into_iter = "warn"
113+
large_digit_groups = "warn"
114+
large_futures = "warn"
115+
large_stack_arrays = "warn"
116+
large_types_passed_by_value = "warn"
117+
linkedlist = "warn"
118+
macro_use_imports = "warn"
119+
manual_assert = "warn"
120+
manual_instant_elapsed = "warn"
121+
manual_is_power_of_two = "warn"
122+
manual_is_variant_and = "warn"
123+
manual_let_else = "warn"
124+
manual_ok_or = "warn"
125+
manual_string_new = "warn"
126+
many_single_char_names = "warn"
127+
map_unwrap_or = "warn"
128+
match_wildcard_for_single_variants = "warn"
129+
maybe_infinite_iter = "warn"
130+
mismatching_type_param_order = "warn"
131+
missing_errors_doc = "allow" # FIXME this triggers 184 times; we should fix most
132+
missing_fields_in_debug = "warn"
133+
missing_panics_doc = "allow" # FIXME this one has 40 triggers
134+
mut_mut = "warn"
135+
naive_bytecount = "warn"
136+
needless_bitwise_bool = "warn"
137+
needless_continue = "warn"
138+
needless_for_each = "warn"
139+
needless_pass_by_value = "warn"
140+
needless_raw_string_hashes = "warn"
141+
no_effect_underscore_binding = "warn"
142+
no_mangle_with_rust_abi = "warn"
143+
option_as_ref_cloned = "warn"
144+
option_option = "warn"
145+
ptr_as_ptr = "warn"
146+
ptr_cast_constness = "warn"
147+
pub_underscore_fields = "warn"
148+
range_minus_one = "warn"
149+
range_plus_one = "warn"
150+
redundant_closure_for_method_calls = "warn"
151+
redundant_else = "warn"
152+
ref_as_ptr = "warn"
153+
ref_binding_to_reference = "warn"
154+
ref_option = "warn"
155+
ref_option_ref = "warn"
156+
return_self_not_must_use = "warn"
157+
same_functions_in_if_condition = "warn"
158+
semicolon_if_nothing_returned = "warn"
159+
should_panic_without_expect = "warn"
160+
single_char_pattern = "warn"
161+
single_match_else = "warn"
162+
stable_sort_primitive = "warn"
163+
str_split_at_newline = "warn"
164+
string_add_assign = "warn"
165+
struct_excessive_bools = "warn"
166+
struct_field_names = "warn"
167+
too_many_lines = "allow" # FIXME 14 triggers for this lint; probably most should be fixed
168+
transmute_ptr_to_ptr = "warn"
169+
trivially_copy_pass_by_ref = "warn"
170+
unchecked_duration_subtraction = "warn"
171+
unicode_not_nfc = "warn"
172+
unnecessary_box_returns = "warn"
173+
unnecessary_join = "warn"
174+
unnecessary_literal_bound = "warn"
175+
unnecessary_wraps = "warn"
176+
unnested_or_patterns = "warn"
177+
unreadable_literal = "warn"
178+
unsafe_derive_deserialize = "warn"
179+
unused_async = "warn"
180+
unused_self = "warn"
181+
used_underscore_binding = "warn"
182+
used_underscore_items = "warn"
183+
verbose_bit_mask = "warn"
184+
wildcard_imports = "warn"
185+
zero_sized_map_values = "warn"

clippy.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
msrv = "1.56.1"
1+
avoid-breaking-exported-api = true
2+
msrv = "1.63.0"

examples/raw_blind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ fn main() {
184184
&mut rng,
185185
&secp,
186186
dest_amt,
187-
Address::p2wsh(
187+
&Address::p2wsh(
188188
&Script::new_v0_wsh(&dest_wsh),
189189
Some(dest_blind_pk.inner),
190190
&PARAMS,
@@ -206,7 +206,7 @@ fn main() {
206206
&mut rng,
207207
&secp,
208208
change_amt,
209-
Address::p2wsh(
209+
&Address::p2wsh(
210210
&Script::new_v0_wsh(&change_wsh),
211211
Some(change_blind_pk.inner),
212212
&PARAMS,

examples/tx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn main() {
3232

3333
let res = tx.verify_tx_amt_proofs(&secp, &[txout]);
3434
match res {
35-
Ok(_) => {}
35+
Ok(()) => {}
3636
Err(e) => {
3737
panic!("{}", e);
3838
}

src/address.rs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,14 @@ impl Address {
430430
version: witver,
431431
program: ref witprog,
432432
} => script::Builder::new()
433-
.push_int(witver.to_u8() as i64)
433+
.push_int(i64::from(witver.to_u8()))
434434
.push_slice(witprog),
435435
}
436436
.into_script()
437437
}
438438

439439
/// Convert this address to an unconfidential address.
440+
#[must_use]
440441
pub fn to_unconfidential(&self) -> Address {
441442
Address {
442443
params: self.params,
@@ -446,6 +447,7 @@ impl Address {
446447
}
447448

448449
/// Convert this address to a confidential address with the given blinding pubkey.
450+
#[must_use]
449451
pub fn to_confidential(&self, blinding_pubkey: secp256k1_zkp::PublicKey) -> Address {
450452
Address {
451453
params: self.params,
@@ -492,19 +494,11 @@ impl Address {
492494
// When blinded, the structure is:
493495
// <1: blinding prefix> <1: regular prefix> <33: blinding pubkey> <20: hash160>
494496

495-
let (blinded, prefix) = match data[0] == params.blinded_prefix {
496-
true => {
497-
if data.len() != 55 {
498-
return Err(AddressError::InvalidLength(data.len()));
499-
}
500-
(true, data[1])
501-
}
502-
false => {
503-
if data.len() != 21 {
504-
return Err(AddressError::InvalidLength(data.len()));
505-
}
506-
(false, data[0])
507-
}
497+
let blinded = data[0] == params.blinded_prefix;
498+
let prefix = match (blinded, data.len()) {
499+
(true, 55) => data[1],
500+
(false, 21) => data[0],
501+
(_, len) => return Err(AddressError::InvalidLength(len)),
508502
};
509503

510504
let (blinding_pubkey, payload_data) = match blinded {
@@ -534,7 +528,7 @@ impl Address {
534528
}
535529

536530
/// Parse the address using the given parameters.
537-
/// When using the built-in parameters, you can use [FromStr].
531+
/// When using the built-in parameters, you can use [`FromStr`].
538532
pub fn parse_with_params(
539533
s: &str,
540534
params: &'static AddressParams,
@@ -670,14 +664,10 @@ fn find_prefix(bech32: &str) -> &str {
670664
/// The first prefix can be mixed case, but the second one is expected in
671665
/// lower case.
672666
fn match_prefix(prefix_mixed: &str, target: Hrp) -> bool {
673-
if target.len() != prefix_mixed.len() {
674-
false
675-
} else {
676-
target
677-
.lowercase_char_iter()
678-
.zip(prefix_mixed.chars())
679-
.all(|(char_lower, char_mixed)| char_lower == char_mixed.to_ascii_lowercase())
680-
}
667+
target.len() == prefix_mixed.len() && target
668+
.lowercase_char_iter()
669+
.zip(prefix_mixed.chars())
670+
.all(|(char_lower, char_mixed)| char_lower == char_mixed.to_ascii_lowercase())
681671
}
682672

683673
impl FromStr for Address {
@@ -692,7 +682,7 @@ impl FromStr for Address {
692682
let net_arr = [liq, ele, liq_test];
693683

694684
let prefix = find_prefix(s);
695-
for net in net_arr.iter() {
685+
for net in &net_arr {
696686
// Bech32.
697687
if match_prefix(prefix, net.bech_hrp) {
698688
return Address::from_bech32(s, false, net);
@@ -712,7 +702,7 @@ impl FromStr for Address {
712702
}
713703

714704
let p = data[0];
715-
for net in net_arr.iter() {
705+
for net in &net_arr {
716706
if p == net.p2pkh_prefix || p == net.p2sh_prefix || p == net.blinded_prefix {
717707
return Address::from_base58(&data, net);
718708
}

0 commit comments

Comments
 (0)