Fix new clippy lint complaining about extra `&`s in `format!()`
What changed, and why it matters
This commit only cleans up Rust formatting strings to satisfy a new Clippy lint. It removes unnecessary ampersands (&) inside format!() and writeln!() calls. There is no change to program logic, no security fix, and no behavior change.
No security action needed. Treat as routine code-quality/maintenance cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is a pure style/refactoring change: it converts positional format arguments like &announcement and &msg.channel_id to inline-capture form {announcement:?} or removes redundant & prefixes. These changes are semantically equivalent because format!() takes arguments by reference automatically and inline captures use the named variable directly. No cryptographic, network, or state-machine logic is modified.
Changed components
lightning/src/ln/channel.rslightning/src/ln/channelmanager.rslightning/src/ln/inbound_payment.rslightning/src/ln/peer_channel_encryptor.rslightning/src/ln/peer_handler.rslightning/src/routing/gossip.rsInspect captured patch +20 / −21
### lightning/src/ln/channel.rs
@@ -13026,13 +13026,13 @@ where
if self.context.secp_ctx.verify_ecdsa(&msghash, &msg.node_signature, &self.context.get_counterparty_node_id()).is_err() {
return Err(ChannelError::close(format!(
- "Bad announcement_signatures. Failed to verify node_signature. UnsignedChannelAnnouncement used for verification is {:?}. their_node_key is {:?}",
- &announcement, self.context.get_counterparty_node_id())));
+ "Bad announcement_signatures. Failed to verify node_signature. UnsignedChannelAnnouncement used for verification is {announcement:?}. their_node_key is {:?}",
+ self.context.get_counterparty_node_id())));
}
if self.context.secp_ctx.verify_ecdsa(&msghash, &msg.bitcoin_signature, self.funding.counterparty_funding_pubkey()).is_err() {
return Err(ChannelError::close(format!(
- "Bad announcement_signatures. Failed to verify bitcoin_signature. UnsignedChannelAnnouncement used for verification is {:?}. their_bitcoin_key is ({:?})",
- &announcement, self.funding.counterparty_funding_pubkey())));
+ "Bad announcement_signatures. Failed to verify bitcoin_signature. UnsignedChannelAnnouncement used for verification is {announcement:?}. their_bitcoin_key is ({:?})",
+ self.funding.counterparty_funding_pubkey())));
}
self.context.announcement_sigs = Some((msg.node_signature, msg.bitcoin_signature));
### lightning/src/ln/channelmanager.rs
@@ -12603,7 +12603,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
"Lost channel state for channel {}.\n\
Received peer storage with a more recent state than what our node had.\n\
Use the FundRecoverer to initiate a force close and sweep the funds.",
- &mon_holder.channel_id
+ mon_holder.channel_id
);
}
}
### lightning/src/ln/inbound_payment.rs
@@ -534,8 +534,7 @@ pub(super) fn get_payment_preimage(
)
.map_err(|bad_preimage_bytes| APIError::APIMisuseError {
err: format!(
- "Payment hash {} did not match decoded preimage {}",
- &payment_hash,
+ "Payment hash {payment_hash} did not match decoded preimage {}",
log_bytes!(bad_preimage_bytes)
),
})?;
### lightning/src/ln/peer_channel_encryptor.rs
@@ -261,7 +261,7 @@ impl PeerChannelEncryptor {
let their_pub = match PublicKey::from_slice(&act[1..34]) {
Err(_) => {
return Err(LightningError {
- err: format!("Invalid public key {}", &act[1..34].as_hex()),
+ err: format!("Invalid public key {}", act[1..34].as_hex()),
action: msgs::ErrorAction::DisconnectPeer { msg: None },
})
},
@@ -472,7 +472,7 @@ impl PeerChannelEncryptor {
Ok(key) => key,
Err(_) => {
return Err(LightningError {
- err: format!("Bad node_id from peer, {}", &their_node_id.as_hex()),
+ err: format!("Bad node_id from peer, {}", their_node_id.as_hex()),
action: msgs::ErrorAction::DisconnectPeer { msg: None },
})
},
### lightning/src/ln/peer_handler.rs
@@ -2236,8 +2236,8 @@ impl<
if let Message::StartBatch(msg) = message {
if peer_lock.message_batch.is_some() {
let error = format!(
- "Peer {} sent start_batch for channel {} before previous batch completed",
- their_node_id, &msg.channel_id
+ "Peer {their_node_id} sent start_batch for channel {} before previous batch completed",
+ msg.channel_id
);
log_debug!(logger, "{}", error);
return Err(LightningError {
@@ -2252,8 +2252,8 @@ impl<
let batch_size = msg.batch_size as usize;
if batch_size <= 1 {
let error = format!(
- "Peer {} sent start_batch for channel {} not strictly greater than 1",
- their_node_id, &msg.channel_id
+ "Peer {their_node_id} sent start_batch for channel {} not strictly greater than 1",
+ msg.channel_id
);
log_debug!(logger, "{}", error);
return Err(LightningError {
@@ -2269,8 +2269,8 @@ impl<
const BATCH_SIZE_LIMIT: usize = 20;
if batch_size > BATCH_SIZE_LIMIT {
let error = format!(
- "Peer {} sent start_batch for channel {} exceeding the limit",
- their_node_id, &msg.channel_id
+ "Peer {their_node_id} sent start_batch for channel {} exceeding the limit",
+ msg.channel_id
);
log_debug!(logger, "{}", error);
return Err(LightningError {
@@ -2310,7 +2310,7 @@ impl<
&mut message_batch.messages;
if msg.channel_id != message_batch.channel_id {
- let error = format!("Peer {} sent batched commitment_signed for the wrong channel (expected: {}, actual: {})", their_node_id, message_batch.channel_id, &msg.channel_id);
+ let error = format!("Peer {their_node_id} sent batched commitment_signed for the wrong channel (expected: {}, actual: {})", message_batch.channel_id, msg.channel_id);
log_debug!(logger, "{}", error);
return Err(LightningError {
err: error.clone(),
### lightning/src/routing/gossip.rs
@@ -1112,9 +1112,9 @@ impl fmt::Display for ChannelInfo {
f,
"features: {}, node_one: {}, one_to_two: {:?}, node_two: {}, two_to_one: {:?}",
log_bytes!(self.features.encode()),
- &self.node_one,
+ self.node_one,
self.one_to_two,
- &self.node_two,
+ self.node_two,
self.two_to_one
)?;
Ok(())
@@ -1730,11 +1730,11 @@ impl<L: Logger> fmt::Display for NetworkGraph<L> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
writeln!(f, "Network map\n[Channels]")?;
for (key, val) in self.channels.read().unwrap().unordered_iter() {
- writeln!(f, " {}: {}", key, val)?;
+ writeln!(f, " {key}: {val}")?;
}
writeln!(f, "[Nodes]")?;
for (&node_id, val) in self.nodes.read().unwrap().unordered_iter() {
- writeln!(f, " {}: {}", &node_id, val)?;
+ writeln!(f, " {node_id}: {val}")?;
}
Ok(())
}
@@ -2193,7 +2193,7 @@ impl<L: Logger> NetworkGraph<L> {
|| removed_nodes.contains_key(&msg.node_id_2)
{
return Err(LightningError{
- err: format!("Channel with SCID {} or one of its nodes was removed from our network graph recently", &msg.short_channel_id),
+ err: format!("Channel with SCID {} or one of its nodes was removed from our network graph recently", msg.short_channel_id),
action: ErrorAction::IgnoreAndLog(Level::Gossip)});
}
}Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.