Skip to content

Commit b1dd3d3

Browse files
committed
Merge #127: Turn on a bunch of cippy ints
8e15fd3 clippy: invert != in if statements (Andrew Poelstra) 3fdacb5 clippy: replace flat_map with filter_map (Andrew Poelstra) 2c7b1fb clippy: don't use .iter and .iter_mut where not necessary (Andrew Poelstra) 9d5a796 clippy: don't use lossless casts (Andrew Poelstra) 53f5610 clippy: use built-in conversion from bool to numeric (Andrew Poelstra) 5130441 clippy: turn on all lints that don't trigger anywhere (Andrew Poelstra) 7a7d16b clippy: copy giant list of lints from bitcoin-units, with all "allow"ed (Andrew Poelstra) 1c2fa51 clippy: whitelist lints that fire on current nightly (Andrew Poelstra) Pull request description: This is the first part of a project to turn on a ton of pedantic Clippy lints. We can choose not to do some if they're too annoying. There are about 20 left after this. ACKs for top commit: uncomputable: ACK 8e15fd3 Looks good to me Tree-SHA512: 3399a80ada2d28e79afbdc484b35c9cc4f3ff053899fa956d51c6bfe64560f98e5d07d46f8566bdc6f204ee047b7c56e552d023b58e90b54c573d86c65c7ff16
2 parents 7770a3c + 8e15fd3 commit b1dd3d3

File tree

7 files changed

+145
-14
lines changed

7 files changed

+145
-14
lines changed

Cargo.toml

+129
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,132 @@ getrandom = { version = "0.2", features = ["js"] }
3838
[workspace]
3939
members = ["codegen"]
4040
exclude = ["fuzz", "bitcoind-tests"]
41+
42+
[lints.clippy]
43+
# Exclude lints we don't think are valuable.
44+
large_enum_variant = "allow" # docs say "measure before paying attention to this"; why is it on by default??
45+
similar_names = "allow" # Too many (subjectively) false positives.
46+
uninlined_format_args = "allow" # This is a subjective style choice.
47+
match_bool = "allow" # Adds extra indentation and LOC.
48+
match_same_arms = "allow" # Collapses things that are conceptually unrelated to each other.
49+
must_use_candidate = "allow" # Useful for audit but many false positives.
50+
# Whitelist the cast lints because sometimes casts are unavoidable. But
51+
# every cast should contain a code comment!
52+
cast_possible_truncation = "allow"
53+
cast_possible_wrap = "allow"
54+
cast_sign_loss = "allow"
55+
# Exhaustive list of pedantic clippy lints
56+
assigning_clones = "warn"
57+
bool_to_int_with_if = "warn"
58+
borrow_as_ptr = "warn"
59+
case_sensitive_file_extension_comparisons = "warn"
60+
cast_lossless = "warn"
61+
cast_precision_loss = "warn"
62+
cast_ptr_alignment = "warn"
63+
checked_conversions = "warn"
64+
cloned_instead_of_copied = "warn"
65+
copy_iterator = "warn"
66+
default_trait_access = "warn"
67+
doc_link_with_quotes = "warn"
68+
doc_markdown = "allow"
69+
empty_enum = "warn"
70+
enum_glob_use = "allow"
71+
expl_impl_clone_on_copy = "warn"
72+
explicit_deref_methods = "warn"
73+
explicit_into_iter_loop = "warn"
74+
explicit_iter_loop = "warn"
75+
filter_map_next = "warn"
76+
flat_map_option = "warn"
77+
float_cmp = "warn"
78+
fn_params_excessive_bools = "warn"
79+
from_iter_instead_of_collect = "warn"
80+
if_not_else = "warn"
81+
ignored_unit_patterns = "allow"
82+
implicit_clone = "warn"
83+
implicit_hasher = "warn"
84+
inconsistent_struct_constructor = "warn"
85+
index_refutable_slice = "warn"
86+
inefficient_to_string = "allow"
87+
inline_always = "warn"
88+
into_iter_without_iter = "warn"
89+
invalid_upcast_comparisons = "warn"
90+
items_after_statements = "allow"
91+
iter_filter_is_ok = "warn"
92+
iter_filter_is_some = "warn"
93+
iter_not_returning_iterator = "warn"
94+
iter_without_into_iter = "warn"
95+
large_digit_groups = "warn"
96+
large_futures = "warn"
97+
large_stack_arrays = "warn"
98+
large_types_passed_by_value = "warn"
99+
linkedlist = "warn"
100+
macro_use_imports = "warn"
101+
manual_assert = "allow"
102+
manual_instant_elapsed = "warn"
103+
manual_is_power_of_two = "warn"
104+
manual_is_variant_and = "warn"
105+
manual_let_else = "allow"
106+
manual_ok_or = "warn"
107+
manual_string_new = "warn"
108+
many_single_char_names = "warn"
109+
map_unwrap_or = "allow"
110+
match_on_vec_items = "warn"
111+
match_wild_err_arm = "warn"
112+
match_wildcard_for_single_variants = "allow"
113+
maybe_infinite_iter = "warn"
114+
mismatching_type_param_order = "warn"
115+
missing_errors_doc = "allow"
116+
missing_fields_in_debug = "warn"
117+
missing_panics_doc = "allow"
118+
mut_mut = "warn"
119+
naive_bytecount = "warn"
120+
needless_bitwise_bool = "warn"
121+
needless_continue = "allow"
122+
needless_for_each = "warn"
123+
needless_pass_by_value = "allow"
124+
needless_raw_string_hashes = "allow"
125+
no_effect_underscore_binding = "warn"
126+
no_mangle_with_rust_abi = "warn"
127+
option_as_ref_cloned = "warn"
128+
option_option = "allow"
129+
ptr_as_ptr = "warn"
130+
ptr_cast_constness = "warn"
131+
pub_underscore_fields = "warn"
132+
range_minus_one = "warn"
133+
range_plus_one = "warn"
134+
redundant_closure_for_method_calls = "allow"
135+
redundant_else = "warn"
136+
ref_as_ptr = "warn"
137+
ref_binding_to_reference = "warn"
138+
ref_option = "warn"
139+
ref_option_ref = "warn"
140+
return_self_not_must_use = "allow"
141+
same_functions_in_if_condition = "warn"
142+
semicolon_if_nothing_returned = "allow"
143+
should_panic_without_expect = "warn"
144+
single_char_pattern = "warn"
145+
single_match_else = "allow"
146+
stable_sort_primitive = "warn"
147+
str_split_at_newline = "warn"
148+
string_add_assign = "warn"
149+
struct_excessive_bools = "warn"
150+
struct_field_names = "warn"
151+
too_many_lines = "allow"
152+
transmute_ptr_to_ptr = "warn"
153+
trivially_copy_pass_by_ref = "warn"
154+
unchecked_duration_subtraction = "warn"
155+
unicode_not_nfc = "warn"
156+
unnecessary_box_returns = "warn"
157+
unnecessary_join = "warn"
158+
unnecessary_literal_bound = "warn"
159+
unnecessary_wraps = "warn"
160+
unnested_or_patterns = "allow"
161+
unreadable_literal = "allow"
162+
unsafe_derive_deserialize = "warn"
163+
unused_async = "warn"
164+
unused_self = "warn"
165+
used_underscore_binding = "warn"
166+
used_underscore_items = "warn"
167+
verbose_bit_mask = "warn"
168+
wildcard_imports = "allow"
169+
zero_sized_map_values = "warn"

clippy.toml

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
msrv = "1.78.0"
2+
# We have an error type, `RichError`, of size 144. This is pushing it but probably fine.
3+
large-error-threshold = 145

src/ast.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1039,27 +1039,27 @@ impl AbstractSyntaxTree for Call {
10391039
parse_args: &[parse::Expression],
10401040
expected_tys: &[ResolvedType],
10411041
) -> Result<(), Error> {
1042-
if parse_args.len() != expected_tys.len() {
1042+
if parse_args.len() == expected_tys.len() {
1043+
Ok(())
1044+
} else {
10431045
Err(Error::InvalidNumberOfArguments(
10441046
expected_tys.len(),
10451047
parse_args.len(),
10461048
))
1047-
} else {
1048-
Ok(())
10491049
}
10501050
}
10511051

10521052
fn check_output_type(
10531053
observed_ty: &ResolvedType,
10541054
expected_ty: &ResolvedType,
10551055
) -> Result<(), Error> {
1056-
if observed_ty != expected_ty {
1056+
if observed_ty == expected_ty {
1057+
Ok(())
1058+
} else {
10571059
Err(Error::ExpressionTypeMismatch(
10581060
expected_ty.clone(),
10591061
observed_ty.clone(),
10601062
))
1061-
} else {
1062-
Ok(())
10631063
}
10641064
}
10651065

src/num.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ impl fmt::Display for U256 {
298298
is_zero = true;
299299

300300
// Divide by 10, starting at the most significant bytes
301-
for byte in bytes.iter_mut() {
302-
let value = carry * 256 + *byte as u32;
301+
for byte in &mut bytes {
302+
let value = carry * 256 + u32::from(*byte);
303303
*byte = (value / 10) as u8;
304304
carry = value % 10;
305305

@@ -334,7 +334,7 @@ impl FromStr for U256 {
334334

335335
// Add to the least significant bytes first
336336
for byte in bytes.iter_mut().rev() {
337-
let value = *byte as u32 * 10 + carry;
337+
let value = u32::from(*byte) * 10 + carry;
338338
*byte = (value % 256) as u8;
339339
carry = value / 256;
340340
}

src/pattern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl BasePattern {
259259

260260
/// Get an iterator over all identifiers inside the pattern.
261261
pub fn identifiers(&self) -> impl Iterator<Item = &Identifier> {
262-
self.pre_order_iter().flat_map(BasePattern::as_identifier)
262+
self.pre_order_iter().filter_map(BasePattern::as_identifier)
263263
}
264264

265265
/// Check if all `identifiers` are contained inside the pattern.

src/serde.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl<'a> Serialize for WitnessMapSerializer<'a> {
144144
S: Serializer,
145145
{
146146
let mut map = serializer.serialize_map(Some(self.0.len()))?;
147-
for (name, value) in self.0.iter() {
147+
for (name, value) in self.0 {
148148
map.serialize_entry(name.as_inner(), &ValueMapSerializer(value))?;
149149
}
150150
map.end()

src/value.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl UIntValue {
155155
let mut byte = 0u8;
156156
for _ in 0..8 {
157157
let bit = padded_bits.next().unwrap();
158-
byte = (byte << 1) | if bit == '1' { 1 } else { 0 };
158+
byte = (byte << 1) | u8::from(bit == '1');
159159
}
160160
bytes.push(byte);
161161
}
@@ -934,7 +934,7 @@ impl ValueConstructible for StructuralValue {
934934

935935
fn array<I: IntoIterator<Item = Self>>(elements: I, ty: Self::Type) -> Self {
936936
let elements: Vec<Self> = elements.into_iter().collect();
937-
for element in elements.iter() {
937+
for element in &elements {
938938
assert!(
939939
element.is_of_type(&ty),
940940
"Element {element} is not of expected type {ty}"
@@ -954,7 +954,7 @@ impl ValueConstructible for StructuralValue {
954954
elements.len() < bound.get(),
955955
"There must be fewer list elements than the bound {bound}"
956956
);
957-
for element in elements.iter() {
957+
for element in &elements {
958958
assert!(
959959
element.is_of_type(&ty),
960960
"Element {element} is not of expected type {ty}"

0 commit comments

Comments
 (0)