Skip to content

Enable a ton of pedantic clippy lints #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
623b2a5
clippy: fix all current clippy lints
apoelstra Jun 25, 2025
396e1d6
bump msrv to 1.63.0; fix new clippy lints
apoelstra Jun 25, 2025
113897d
clippy: fix bool_to_int_with_if lint
apoelstra Jun 25, 2025
dbd8821
clippy: fix the cast_lossless lint
apoelstra Jun 25, 2025
0eb9aa6
clippy: fix cloned_instead_of_copied lint
apoelstra Jun 25, 2025
3f12046
clippy: fix default_trait_access lint
apoelstra Jun 25, 2025
ad2eaac
clippy: fix `doc_markdown` lint
apoelstra Jun 25, 2025
d2b998b
clippy: fix explicit-iter-loop and explicit-into-iter-loop lints
apoelstra Jun 25, 2025
6db0383
clippy: fix if_not_else lint
apoelstra Jun 25, 2025
8abf2ba
clippy: fix the `ignored_unit_patterns` lint
apoelstra Jun 25, 2025
90c4f38
clippy: fix the `items_after_statemnts` lint
apoelstra Jun 25, 2025
b339010
clippy: fix many_single_char_names lint
apoelstra Jun 25, 2025
41cda57
clippy: fix map_unwrap_or lint
apoelstra Jun 25, 2025
2192bef
clippy: fix the match_wildcard_for_single_variants lint
apoelstra Jun 25, 2025
c19097a
clippy: fix `needless_continue` lint
apoelstra Jun 25, 2025
e523b12
clippy: fix `needless_pass_by_value` lint
apoelstra Jun 25, 2025
e536bd4
clippy: fix `range_plus_one` lint; eliminates a hidden panic path
apoelstra Jun 25, 2025
30c40a3
clippy: fix `redundant_closure_for_method_calls` lint
apoelstra Jun 25, 2025
959f8b9
clippy: fix `redundant_else` lint
apoelstra Jun 25, 2025
35ee8f3
clippy: fix `ref_binding_to_reference` lint
apoelstra Jun 25, 2025
372d5d6
clippy: fix `return_self_not_must_use`
apoelstra Jun 25, 2025
64d6853
clippy: fix the `semicolon_if_nothing_returned` lint
apoelstra Jun 25, 2025
c009837
clippy: fix `single_match_else` lint
apoelstra Jun 25, 2025
a314993
clippy: fix `unnested_or_patterns` pattern
apoelstra Jun 25, 2025
3ab34e4
clippy: fix `unreadable_literal` lint
apoelstra Jun 25, 2025
0fd2246
clippy: whitelist one instance of `clippy::wildcard-imports` lint
apoelstra Jun 25, 2025
d68dee5
clippy: fix `enum_glob_use` lint
apoelstra Jun 25, 2025
57c81d3
clippy: enable a ton of pedantic lints (list cribbed from hex-conserv…
apoelstra Jun 25, 2025
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: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ jobs:
run: ./contrib/test.sh

MSRV:
name: Test - 1.56.1 toolchain
name: Test - 1.63.0 toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout Crate
uses: actions/checkout@v3
- name: Checkout Toolchain
uses: dtolnay/rust-toolchain@1.56.1
uses: dtolnay/rust-toolchain@1.63.0
- name: Running test script
env:
DO_DOCS: false
Expand Down
126 changes: 126 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,129 @@ name = "tx"
[workspace]
members = ["elementsd-tests"]
exclude = ["fuzz"]

[lints.clippy]
# Exclude lints we don't think are valuable.
needless_question_mark = "allow" # https://github.com/rust-bitcoin/rust-bitcoin/pull/2134
manual_range_contains = "allow" # More readable than clippy's format.
uninlined_format_args = "allow" # This is a subjective style choice.
float_cmp = "allow" # Bitcoin floats are typically limited to 8 decimal places and we want them exact.
match_bool = "allow" # Adds extra indentation and LOC.
match_same_arms = "allow" # Collapses things that are conceptually unrelated to each other.
must_use_candidate = "allow" # Useful for audit but many false positives.
similar_names = "allow" # Too many (subjectively) false positives.
# Exhaustive list of pedantic clippy lints
assigning_clones = "warn"
bool_to_int_with_if = "warn"
borrow_as_ptr = "warn"
case_sensitive_file_extension_comparisons = "warn"
cast_lossless = "warn"
cast_possible_truncation = "allow" # All casts should include a code comment (except test code).
cast_possible_wrap = "allow" # Same as above re code comment.
cast_precision_loss = "warn"
cast_ptr_alignment = "warn"
cast_sign_loss = "allow" # All casts should include a code comment (except in test code).
checked_conversions = "warn"
cloned_instead_of_copied = "warn"
copy_iterator = "warn"
default_trait_access = "warn"
doc_link_with_quotes = "warn"
doc_markdown = "warn"
empty_enum = "warn"
enum_glob_use = "warn"
expl_impl_clone_on_copy = "warn"
explicit_deref_methods = "warn"
explicit_into_iter_loop = "warn"
explicit_iter_loop = "warn"
filter_map_next = "warn"
flat_map_option = "warn"
fn_params_excessive_bools = "warn"
from_iter_instead_of_collect = "warn"
if_not_else = "warn"
ignored_unit_patterns = "warn"
implicit_clone = "warn"
implicit_hasher = "warn"
inconsistent_struct_constructor = "warn"
index_refutable_slice = "warn"
inefficient_to_string = "warn"
inline_always = "warn"
into_iter_without_iter = "warn"
invalid_upcast_comparisons = "warn"
items_after_statements = "warn"
iter_filter_is_ok = "warn"
iter_filter_is_some = "warn"
iter_not_returning_iterator = "warn"
iter_without_into_iter = "warn"
large_digit_groups = "warn"
large_futures = "warn"
large_stack_arrays = "warn"
large_types_passed_by_value = "warn"
linkedlist = "warn"
macro_use_imports = "warn"
manual_assert = "warn"
manual_instant_elapsed = "warn"
manual_is_power_of_two = "warn"
manual_is_variant_and = "warn"
manual_let_else = "warn"
manual_ok_or = "warn"
manual_string_new = "warn"
many_single_char_names = "warn"
map_unwrap_or = "warn"
match_wildcard_for_single_variants = "warn"
maybe_infinite_iter = "warn"
mismatching_type_param_order = "warn"
missing_errors_doc = "allow" # FIXME this triggers 184 times; we should fix most
missing_fields_in_debug = "warn"
missing_panics_doc = "allow" # FIXME this one has 40 triggers
mut_mut = "warn"
naive_bytecount = "warn"
needless_bitwise_bool = "warn"
needless_continue = "warn"
needless_for_each = "warn"
needless_pass_by_value = "warn"
needless_raw_string_hashes = "warn"
no_effect_underscore_binding = "warn"
no_mangle_with_rust_abi = "warn"
option_as_ref_cloned = "warn"
option_option = "warn"
ptr_as_ptr = "warn"
ptr_cast_constness = "warn"
pub_underscore_fields = "warn"
range_minus_one = "warn"
range_plus_one = "warn"
redundant_closure_for_method_calls = "warn"
redundant_else = "warn"
ref_as_ptr = "warn"
ref_binding_to_reference = "warn"
ref_option = "warn"
ref_option_ref = "warn"
return_self_not_must_use = "warn"
same_functions_in_if_condition = "warn"
semicolon_if_nothing_returned = "warn"
should_panic_without_expect = "warn"
single_char_pattern = "warn"
single_match_else = "warn"
stable_sort_primitive = "warn"
str_split_at_newline = "warn"
string_add_assign = "warn"
struct_excessive_bools = "warn"
struct_field_names = "warn"
too_many_lines = "allow" # FIXME 14 triggers for this lint; probably most should be fixed
transmute_ptr_to_ptr = "warn"
trivially_copy_pass_by_ref = "warn"
unchecked_duration_subtraction = "warn"
unicode_not_nfc = "warn"
unnecessary_box_returns = "warn"
unnecessary_join = "warn"
unnecessary_literal_bound = "warn"
unnecessary_wraps = "warn"
unnested_or_patterns = "warn"
unreadable_literal = "warn"
unsafe_derive_deserialize = "warn"
unused_async = "warn"
unused_self = "warn"
used_underscore_binding = "warn"
used_underscore_items = "warn"
verbose_bit_mask = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"
3 changes: 2 additions & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
msrv = "1.56.1"
avoid-breaking-exported-api = true
msrv = "1.63.0"
4 changes: 2 additions & 2 deletions examples/raw_blind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ fn main() {
&mut rng,
&secp,
dest_amt,
Address::p2wsh(
&Address::p2wsh(
&Script::new_v0_wsh(&dest_wsh),
Some(dest_blind_pk.inner),
&PARAMS,
Expand All @@ -206,7 +206,7 @@ fn main() {
&mut rng,
&secp,
change_amt,
Address::p2wsh(
&Address::p2wsh(
&Script::new_v0_wsh(&change_wsh),
Some(change_blind_pk.inner),
&PARAMS,
Expand Down
2 changes: 1 addition & 1 deletion examples/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() {

let res = tx.verify_tx_amt_proofs(&secp, &[txout]);
match res {
Ok(_) => {}
Ok(()) => {}
Err(e) => {
panic!("{}", e);
}
Expand Down
40 changes: 15 additions & 25 deletions src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,14 @@ impl Address {
version: witver,
program: ref witprog,
} => script::Builder::new()
.push_int(witver.to_u8() as i64)
.push_int(i64::from(witver.to_u8()))
.push_slice(witprog),
}
.into_script()
}

/// Convert this address to an unconfidential address.
#[must_use]
pub fn to_unconfidential(&self) -> Address {
Address {
params: self.params,
Expand All @@ -446,6 +447,7 @@ impl Address {
}

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

let (blinded, prefix) = match data[0] == params.blinded_prefix {
true => {
if data.len() != 55 {
return Err(AddressError::InvalidLength(data.len()));
}
(true, data[1])
}
false => {
if data.len() != 21 {
return Err(AddressError::InvalidLength(data.len()));
}
(false, data[0])
}
let blinded = data[0] == params.blinded_prefix;
let prefix = match (blinded, data.len()) {
(true, 55) => data[1],
(false, 21) => data[0],
(_, len) => return Err(AddressError::InvalidLength(len)),
};

let (blinding_pubkey, payload_data) = match blinded {
Expand Down Expand Up @@ -534,7 +528,7 @@ impl Address {
}

/// Parse the address using the given parameters.
/// When using the built-in parameters, you can use [FromStr].
/// When using the built-in parameters, you can use [`FromStr`].
pub fn parse_with_params(
s: &str,
params: &'static AddressParams,
Expand Down Expand Up @@ -670,14 +664,10 @@ fn find_prefix(bech32: &str) -> &str {
/// The first prefix can be mixed case, but the second one is expected in
/// lower case.
fn match_prefix(prefix_mixed: &str, target: Hrp) -> bool {
if target.len() != prefix_mixed.len() {
false
} else {
target
.lowercase_char_iter()
.zip(prefix_mixed.chars())
.all(|(char_lower, char_mixed)| char_lower == char_mixed.to_ascii_lowercase())
}
target.len() == prefix_mixed.len() && target
.lowercase_char_iter()
.zip(prefix_mixed.chars())
.all(|(char_lower, char_mixed)| char_lower == char_mixed.to_ascii_lowercase())
}

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

let prefix = find_prefix(s);
for net in net_arr.iter() {
for net in &net_arr {
// Bech32.
if match_prefix(prefix, net.bech_hrp) {
return Address::from_bech32(s, false, net);
Expand All @@ -712,7 +702,7 @@ impl FromStr for Address {
}

let p = data[0];
for net in net_arr.iter() {
for net in &net_arr {
if p == net.p2pkh_prefix || p == net.p2sh_prefix || p == net.blinded_prefix {
return Address::from_base58(&data, net);
}
Expand Down
Loading