Add clippy ignore rules for all errors and warnings

This commit is contained in:
Mirebella 2024-08-13 13:41:16 +02:00
parent 5e62df7f20
commit 6ff1978eba
21 changed files with 129 additions and 45 deletions

View file

@ -251,7 +251,94 @@ jobs:
rustup component add clippy
- name: Run default clippy linting
run: |
cargo clippy -- -Aclippy::erasing_op -Aclippy::never_loop -Aclippy::if_same_then_else -Dclippy::try_err
RUSTFLAGS='-D warnings' cargo clippy -- \
`# Errors` \
-A clippy::erasing_op \
-A clippy::never_loop \
`# Warnings` \
-A renamed_and_removed_lints \
-A clippy::blocks_in_conditions \
-A clippy::borrow_deref_ref \
-A clippy::clone_on_copy \
-A clippy::collapsible_else_if \
-A clippy::collapsible_if \
-A clippy::collapsible_match \
-A clippy::comparison_chain \
-A clippy::drain_collect \
-A clippy::drop_non_drop \
-A clippy::enum_variant_names \
-A clippy::explicit_auto_deref \
-A clippy::extra_unused_lifetimes \
-A clippy::for_kv_map \
-A clippy::from_over_into \
-A clippy::get_first \
-A clippy::identity_op \
-A clippy::if_same_then_else \
-A clippy::inconsistent_digit_grouping \
-A clippy::iter_kv_map \
-A clippy::iter_skip_next \
-A clippy::large_enum_variant \
-A clippy::legacy_numeric_constants \
-A clippy::len_without_is_empty \
-A clippy::len_zero \
-A clippy::let_and_return \
-A clippy::manual_filter \
-A clippy::manual_map \
-A clippy::manual_memcpy \
-A clippy::manual_range_contains \
-A clippy::manual_range_patterns \
-A clippy::manual_saturating_arithmetic \
-A clippy::manual_strip \
-A clippy::map_clone \
-A clippy::map_flatten \
-A clippy::match_like_matches_macro \
-A clippy::match_ref_pats \
-A clippy::multiple_bound_locations \
-A clippy::mut_mutex_lock \
-A clippy::needless_bool \
-A clippy::needless_borrow \
-A clippy::needless_borrowed_reference \
-A clippy::needless_borrows_for_generic_args \
-A clippy::needless_lifetimes \
-A clippy::needless_question_mark \
-A clippy::needless_range_loop \
-A clippy::needless_return \
-A clippy::new_without_default \
-A clippy::non_minimal_cfg \
-A clippy::op_ref \
-A clippy::option_as_ref_deref \
-A clippy::option_map_or_none \
-A clippy::option_map_unit_fn \
-A clippy::precedence \
-A clippy::ptr_arg \
-A clippy::question_mark \
-A clippy::readonly_write_lock \
-A clippy::redundant_closure \
-A clippy::redundant_field_names \
-A clippy::redundant_guards \
-A clippy::redundant_pattern_matching \
-A clippy::redundant_slicing \
-A clippy::redundant_static_lifetimes \
-A clippy::result_large_err \
-A clippy::result_unit_err \
-A clippy::search_is_some \
-A clippy::single_char_pattern \
-A clippy::single_match \
-A clippy::slow_vector_initialization \
-A clippy::tabs_in_doc_comments \
-A clippy::to_string_in_format_args \
-A clippy::too_many_arguments \
-A clippy::toplevel_ref_arg \
-A clippy::type_complexity \
-A clippy::unnecessary_cast \
-A clippy::unnecessary_get_then_check \
-A clippy::unnecessary_lazy_evaluations \
-A clippy::unnecessary_mut_passed \
-A clippy::unnecessary_sort_by \
-A clippy::unnecessary_to_owned \
-A clippy::unnecessary_unwrap \
-A clippy::unused_unit \
-A clippy::useless_conversion
rustfmt:
runs-on: ubuntu-latest

View file

@ -176,7 +176,7 @@ where
.and_then(|node| node.announcement_info.as_ref())
.map(|info| {
synthetic_node_announcement.features = info.features().clone();
synthetic_node_announcement.rgb = info.rgb().clone();
synthetic_node_announcement.rgb.clone_from(&info.rgb());
synthetic_node_announcement.alias = info.alias().clone();
synthetic_node_announcement.addresses = info.addresses().to_vec();
});

View file

@ -761,7 +761,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
for outpoint in req.outpoints() {
log_info!(logger, " Outpoint {}", outpoint);
}
self.locktimed_packages.entry(package_locktime).or_insert(Vec::new()).push(req);
self.locktimed_packages.entry(package_locktime).or_default().push(req);
continue;
}

View file

@ -1033,8 +1033,7 @@ impl PackageTemplate {
pub (crate) fn build_package(txid: Txid, vout: u32, input_solving_data: PackageSolvingData, soonest_conf_deadline: u32, height_original: u32) -> Self {
let (malleability, aggregable) = PackageSolvingData::map_output_type_flags(&input_solving_data);
let mut inputs = Vec::with_capacity(1);
inputs.push((BitcoinOutPoint { txid, vout }, input_solving_data));
let inputs = vec![(BitcoinOutPoint { txid, vout }, input_solving_data)];
PackageTemplate {
inputs,
malleability,

View file

@ -176,7 +176,7 @@ mod real_chacha {
) {
let block = ChaCha20::get_single_block(key, nonce);
for i in 0..bytes.len() {
bytes[i] = block[i] ^ bytes[i];
bytes[i] ^= block[i];
}
}

View file

@ -59,7 +59,7 @@ mod real_chachapoly {
pub fn encrypt(&mut self, input: &[u8], output: &mut [u8], out_tag: &mut [u8]) {
assert!(input.len() == output.len());
assert!(self.finished == false);
assert!(!self.finished);
self.cipher.process(input, output);
self.data_len += input.len();
self.mac.input(output);
@ -78,7 +78,7 @@ mod real_chachapoly {
// Encrypt `input_output` in-place. To finish and calculate the tag, use `finish_and_get_tag`
// below.
pub(in super::super) fn encrypt_in_place(&mut self, input_output: &mut [u8]) {
debug_assert!(self.finished == false);
debug_assert!(!self.finished);
self.cipher.process_in_place(input_output);
self.data_len += input_output.len();
self.mac.input(input_output);
@ -87,7 +87,7 @@ mod real_chachapoly {
// If we were previously encrypting with `encrypt_in_place`, this method can be used to finish
// encrypting and calculate the tag.
pub(in super::super) fn finish_and_get_tag(&mut self, out_tag: &mut [u8]) {
debug_assert!(self.finished == false);
debug_assert!(!self.finished);
ChaCha20Poly1305RFC::pad_mac_16(&mut self.mac, self.data_len);
self.finished = true;
self.mac.input(&self.aad_len.to_le_bytes());
@ -100,7 +100,7 @@ mod real_chachapoly {
/// this decryption is *variable time*.
pub fn variable_time_decrypt(&mut self, input: &[u8], output: &mut [u8], tag: &[u8]) -> Result<(), ()> {
assert!(input.len() == output.len());
assert!(self.finished == false);
assert!(!self.finished);
self.finished = true;
@ -131,7 +131,7 @@ mod real_chachapoly {
///
/// Should never be `pub` because the public API should always enforce tag checking.
pub(in super::super) fn decrypt_in_place(&mut self, input_output: &mut [u8]) {
debug_assert!(self.finished == false);
debug_assert!(!self.finished);
self.mac.input(input_output);
self.data_len += input_output.len();
self.cipher.process_in_place(input_output);
@ -140,7 +140,7 @@ mod real_chachapoly {
/// If we were previously decrypting with `just_decrypt_in_place`, this method must be used
/// to check the tag. Returns whether or not the tag is valid.
pub(in super::super) fn finish_and_check_tag(&mut self, tag: &[u8]) -> bool {
debug_assert!(self.finished == false);
debug_assert!(!self.finished);
self.finished = true;
ChaCha20Poly1305RFC::pad_mac_16(&mut self.mac, self.data_len);
self.mac.input(&self.aad_len.to_le_bytes());

View file

@ -82,7 +82,7 @@ impl Poly1305 {
d2 += c as u64; c = (d2 >> 26) as u32; h2 = d2 as u32 & 0x3ffffff;
d3 += c as u64; c = (d3 >> 26) as u32; h3 = d3 as u32 & 0x3ffffff;
d4 += c as u64; c = (d4 >> 26) as u32; h4 = d4 as u32 & 0x3ffffff;
h0 += c * 5; c = h0 >> 26; h0 = h0 & 0x3ffffff;
h0 += c * 5; c = h0 >> 26; h0 &= 0x3ffffff;
h1 += c;
self.h[0] = h0;
@ -111,11 +111,11 @@ impl Poly1305 {
let mut h4 = self.h[4];
let mut c : u32;
c = h1 >> 26; h1 = h1 & 0x3ffffff;
h2 += c; c = h2 >> 26; h2 = h2 & 0x3ffffff;
h3 += c; c = h3 >> 26; h3 = h3 & 0x3ffffff;
h4 += c; c = h4 >> 26; h4 = h4 & 0x3ffffff;
h0 += c * 5; c = h0 >> 26; h0 = h0 & 0x3ffffff;
c = h1 >> 26; h1 &= 0x3ffffff;
h2 += c; c = h2 >> 26; h2 &= 0x3ffffff;
h3 += c; c = h3 >> 26; h3 &= 0x3ffffff;
h4 += c; c = h4 >> 26; h4 &= 0x3ffffff;
h0 += c * 5; c = h0 >> 26; h0 &= 0x3ffffff;
h1 += c;
// compute h + -p

View file

@ -1271,6 +1271,7 @@ pub enum Event {
///
/// This field will be `None` for objects serialized prior to LDK 0.0.117.
channel_capacity_sats: Option<u64>,
/// The original channel funding TXO; this helps checking for the existence and confirmation
/// status of the closing tx.
/// Note that for instances serialized in v0.0.119 or prior this will be missing (None).
@ -2049,7 +2050,7 @@ impl MaybeReadable for Event {
payment_hash,
purpose: _init_tlv_based_struct_field!(purpose, upgradable_required),
amount_msat,
htlcs: htlcs.unwrap_or(vec![]),
htlcs: htlcs.unwrap_or_default(),
sender_intended_total_msat,
onion_fields,
}))

View file

@ -221,13 +221,12 @@ pub fn build_commitment_secret(commitment_seed: &[u8; 32], idx: u64) -> [u8; 32]
/// Build a closing transaction
pub fn build_closing_transaction(to_holder_value_sat: Amount, to_counterparty_value_sat: Amount, to_holder_script: ScriptBuf, to_counterparty_script: ScriptBuf, funding_outpoint: OutPoint) -> Transaction {
let txins = {
let mut ins: Vec<TxIn> = Vec::new();
ins.push(TxIn {
let ins: Vec<TxIn> = vec![TxIn {
previous_output: funding_outpoint,
script_sig: ScriptBuf::new(),
sequence: Sequence::MAX,
witness: Witness::new(),
});
}];
ins
};
@ -702,8 +701,7 @@ pub(crate) fn make_funding_redeemscript_from_slices(broadcaster_funding_key: &[u
/// Panics if htlc.transaction_output_index.is_none() (as such HTLCs do not appear in the
/// commitment transaction).
pub fn build_htlc_transaction(commitment_txid: &Txid, feerate_per_kw: u32, contest_delay: u16, htlc: &HTLCOutputInCommitment, channel_type_features: &ChannelTypeFeatures, broadcaster_delayed_payment_key: &DelayedPaymentKey, revocation_key: &RevocationKey) -> Transaction {
let mut txins: Vec<TxIn> = Vec::new();
txins.push(build_htlc_input(commitment_txid, htlc, channel_type_features));
let txins= vec![build_htlc_input(commitment_txid, htlc, channel_type_features)];
let mut txouts: Vec<TxOut> = Vec::new();
txouts.push(build_htlc_output(
@ -1590,14 +1588,13 @@ impl CommitmentTransaction {
commitment_transaction_number_obscure_factor ^ (INITIAL_COMMITMENT_NUMBER - commitment_number);
let txins = {
let mut ins: Vec<TxIn> = Vec::new();
ins.push(TxIn {
let ins: Vec<TxIn> = vec![TxIn {
previous_output: channel_parameters.funding_outpoint(),
script_sig: ScriptBuf::new(),
sequence: Sequence(((0x80 as u32) << 8 * 3)
| ((obscured_commitment_transaction_number >> 3 * 8) as u32)),
witness: Witness::new(),
});
}];
ins
};
(obscured_commitment_transaction_number, txins)

View file

@ -610,7 +610,7 @@ impl ChannelState {
}
}
fn to_u32(&self) -> u32 {
fn to_u32(self) -> u32 {
match self {
ChannelState::NegotiatingFunding(flags) => flags.0,
ChannelState::FundingNegotiated => state_flags::FUNDING_NEGOTIATED,
@ -9505,7 +9505,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
monitor_pending_forwards,
monitor_pending_failures,
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
monitor_pending_update_adds: monitor_pending_update_adds.unwrap_or(Vec::new()),
monitor_pending_update_adds: monitor_pending_update_adds.unwrap_or_default(),
signer_pending_revoke_and_ack: false,
signer_pending_commitment_update: false,

View file

@ -5165,7 +5165,7 @@ where
failure_code: fail_malformed_htlc.failure_code,
},
};
self.forward_htlcs.lock().unwrap().entry(incoming_scid).or_insert(vec![]).push(failure);
self.forward_htlcs.lock().unwrap().entry(incoming_scid).or_default().push(failure);
self.pending_events.lock().unwrap().push_back((events::Event::HTLCHandlingFailed {
prev_channel_id: incoming_channel_id,
failed_next_destination: htlc_destination,
@ -6770,7 +6770,7 @@ where
peer_state.actions_blocking_raa_monitor_updates
.entry(prev_hop.channel_id)
.or_insert_with(Vec::new)
.or_default()
.push(raa_blocker);
} else {
debug_assert!(false,

View file

@ -1431,7 +1431,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
let peer = &mut *peer_lock;
let mut msg_to_handle = None;
if peer_node_id.is_none() {
peer_node_id = peer.their_node_id.clone();
peer_node_id.clone_from(&peer.their_node_id);
}
assert!(peer.pending_read_buffer.len() > 0);

View file

@ -1018,7 +1018,7 @@ impl InvoiceContents {
self.fields().fallbacks
.as_ref()
.map(|fallbacks| filter_fallbacks(self.chain(), fallbacks))
.unwrap_or_else(Vec::new)
.unwrap_or_default()
}
fn features(&self) -> &Bolt12InvoiceFeatures {

View file

@ -1048,7 +1048,7 @@ pub enum Quantity {
}
impl Quantity {
fn to_tlv_record(&self) -> Option<u64> {
fn to_tlv_record(self) -> Option<u64> {
match self {
Quantity::Bounded(n) => Some(n.get()),
Quantity::Unbounded => Some(0),

View file

@ -240,7 +240,7 @@ impl MetadataMaterial {
self.hmac.input(DERIVED_METADATA_HMAC_INPUT);
self.maybe_include_encrypted_payment_id();
let mut bytes = self.encrypted_payment_id.map(|id| id.to_vec()).unwrap_or(vec![]);
let mut bytes = self.encrypted_payment_id.map(|id| id.to_vec()).unwrap_or_default();
bytes.extend_from_slice(self.nonce.as_slice());
bytes.extend_from_slice(Hmac::from_engine(self.hmac).as_byte_array());
bytes
@ -256,7 +256,7 @@ impl MetadataMaterial {
self.hmac.input(DERIVED_METADATA_AND_KEYS_HMAC_INPUT);
self.maybe_include_encrypted_payment_id();
let bytes = self.encrypted_payment_id.map(|id| id.to_vec()).unwrap_or(vec![]);
let bytes = self.encrypted_payment_id.map(|id| id.to_vec()).unwrap_or_default();
let hmac = Hmac::from_engine(self.hmac);
let privkey = SecretKey::from_slice(hmac.as_byte_array()).unwrap();

View file

@ -509,10 +509,10 @@ where U::Target: UtxoLookup, L::Target: Logger
let mut one_to_two_announcement: Option<msgs::ChannelUpdate> = None;
let mut two_to_one_announcement: Option<msgs::ChannelUpdate> = None;
if let Some(one_to_two) = chan.one_to_two.as_ref() {
one_to_two_announcement = one_to_two.last_update_message.clone();
one_to_two_announcement.clone_from(&one_to_two.last_update_message);
}
if let Some(two_to_one) = chan.two_to_one.as_ref() {
two_to_one_announcement = two_to_one.last_update_message.clone();
two_to_one_announcement.clone_from(&two_to_one.last_update_message);
}
return Some((chan_announcement, one_to_two_announcement, two_to_one_announcement));
} else {

View file

@ -1704,7 +1704,7 @@ where L::Target: Logger {
.filter(|(p, _)| p.blinded_hops().len() == 1)
.any(|(_, iter_info_opt)| iter_info_opt.is_some() && iter_info_opt != info_opt)
{
return Err(LightningError{err: format!("1-hop blinded paths must all have matching introduction node ids"), action: ErrorAction::IgnoreError});
return Err(LightningError{err: "1-hop blinded paths must all have matching introduction node ids".to_string(), action: ErrorAction::IgnoreError});
}
}
}

View file

@ -1587,7 +1587,7 @@ mod bucketed_history {
}
impl LegacyHistoricalBucketRangeTracker {
pub(crate) fn into_current(&self) -> HistoricalBucketRangeTracker {
pub(crate) fn into_current(self) -> HistoricalBucketRangeTracker {
let mut buckets = [0; 32];
for (idx, legacy_bucket) in self.buckets.iter().enumerate() {
let mut new_val = *legacy_bucket;

View file

@ -512,9 +512,9 @@ impl PendingChecks {
if let Some(msg) = full_msg { ChannelAnnouncement::Full(msg.clone()) }
else { ChannelAnnouncement::Unsigned(msg.clone()) });
pending_checks.nodes.entry(msg.node_id_1)
.or_insert(Vec::new()).push(Arc::downgrade(&future.state));
.or_default().push(Arc::downgrade(&future.state));
pending_checks.nodes.entry(msg.node_id_2)
.or_insert(Vec::new()).push(Arc::downgrade(&future.state));
.or_default().push(Arc::downgrade(&future.state));
Err(LightningError {
err: "Channel being checked async".to_owned(),
action: ErrorAction::IgnoreAndLog(Level::Gossip),

View file

@ -128,11 +128,11 @@ impl<K: Clone + Hash + Ord, V> IndexedMap<K, V> {
let start = match range.start_bound() {
Bound::Unbounded => 0,
Bound::Included(key) => self.keys.binary_search(key).unwrap_or_else(|index| index),
Bound::Excluded(key) => self.keys.binary_search(key).and_then(|index| Ok(index + 1)).unwrap_or_else(|index| index),
Bound::Excluded(key) => self.keys.binary_search(key).map(|index| index +1).unwrap_or_else(|index| index),
};
let end = match range.end_bound() {
Bound::Unbounded => self.keys.len(),
Bound::Included(key) => self.keys.binary_search(key).and_then(|index| Ok(index + 1)).unwrap_or_else(|index| index),
Bound::Included(key) => self.keys.binary_search(key).map(|index| index +1).unwrap_or_else(|index| index),
Bound::Excluded(key) => self.keys.binary_search(key).unwrap_or_else(|index| index),
};

View file

@ -247,7 +247,7 @@ impl<T: fmt::Display, I: core::iter::Iterator<Item = T> + Clone> fmt::Display fo
if let Some(item) = iter.next() {
write!(f, "{}", item)?;
}
while let Some(item) = iter.next() {
for item in iter {
write!(f, ", {}", item)?;
}
write!(f, "]")?;