Skip to content

Commit 89f15b6

Browse files
authored
Merge pull request #36 from x100111010/rust_1.86
style: fix clippy rust 1.86
2 parents 82a8b13 + acfea65 commit 89f15b6

File tree

15 files changed

+32
-29
lines changed

15 files changed

+32
-29
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ISC License
22

3-
Copyright (c) 2024-2024 Spectre developers
3+
Copyright (c) 2024-2025 Spectre developers
44
Copyright (c) 2022-2024 Kaspa developers
55

66
Permission to use, copy, modify, and distribute this software for any

cli/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ impl SpectreCli {
807807
}
808808
SyncState::UtxoResync => Some([style("SYNC").red().to_string(), style("UTXO").black().to_string()].join(" ")),
809809
SyncState::NotSynced => Some([style("SYNC").red().to_string(), style("...").black().to_string()].join(" ")),
810-
SyncState::Synced { .. } => None,
810+
SyncState::Synced => None,
811811
}
812812
} else {
813813
Some(style("SYNC").red().to_string())

components/addressmanager/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl AddressManager {
227227
ExtendHelper { gateway, local_addr, external_port: desired_external_port },
228228
)))
229229
}
230-
Err(AddPortError::PortInUse {}) => {
230+
Err(AddPortError::PortInUse) => {
231231
let port = gateway.add_any_port(
232232
igd::PortMappingProtocol::TCP,
233233
local_addr,

consensus/src/pipeline/pruning_processor/processor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl PruningProcessor {
361361
info!(
362362
"Header and Block pruning: pruned {} tips: {}...{}",
363363
pruned_tips.len(),
364-
pruned_tips.iter().take(5.min((pruned_tips.len() + 1) / 2)).reusable_format(", "),
364+
pruned_tips.iter().take(5.min(pruned_tips.len().div_ceil(2))).reusable_format(", "),
365365
pruned_tips.iter().rev().take(5.min(pruned_tips.len() / 2)).reusable_format(", ")
366366
)
367367
}

consensus/src/processes/past_median_time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<T: HeaderStoreReader> SampledPastMedianTimeManager<T> {
5454
window_timestamps.sort_unstable(); // This is deterministic because we sort u64
5555
let avg_frame_size = window_timestamps.len().min(AVERAGE_FRAME_SIZE);
5656
// Define the slice so that the average is the highest among the 2 possible solutions in case of an even frame size
57-
let ending_index = (window_timestamps.len() + avg_frame_size + 1) / 2;
57+
let ending_index = (window_timestamps.len() + avg_frame_size).div_ceil(2);
5858
let timestamp = (window_timestamps[ending_index - avg_frame_size..ending_index].iter().sum::<u64>()
5959
+ avg_frame_size as u64 / 2)
6060
/ avg_frame_size as u64;

crypto/txscript/src/script_builder.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl Default for ScriptBuilder {
281281
#[cfg(test)]
282282
mod tests {
283283
use super::*;
284-
use std::iter::{once, repeat};
284+
use std::iter::once;
285285

286286
// Tests that pushing opcodes to a script via the ScriptBuilder API works as expected.
287287
#[test]
@@ -433,39 +433,39 @@ mod tests {
433433
Test {
434434
name: "push data len 17",
435435
data: vec![0x49; 17],
436-
expected: Ok(once(OpData17).chain(repeat(0x49).take(17)).collect()),
436+
expected: Ok(once(OpData17).chain(std::iter::repeat_n(0x49, 17)).collect()),
437437
unchecked: false,
438438
},
439439
Test {
440440
name: "push data len 75",
441441
data: vec![0x49; 75],
442-
expected: Ok(once(OpData75).chain(repeat(0x49).take(75)).collect()),
442+
expected: Ok(once(OpData75).chain(std::iter::repeat_n(0x49, 75)).collect()),
443443
unchecked: false,
444444
},
445445
// BIP0062: Pushing 76 to 255 bytes must use OP_PUSHDATA1.
446446
Test {
447447
name: "push data len 76",
448448
data: vec![0x49; 76],
449-
expected: Ok(once(OpPushData1).chain(once(76)).chain(repeat(0x49).take(76)).collect()),
449+
expected: Ok(once(OpPushData1).chain(once(76)).chain(std::iter::repeat_n(0x49, 76)).collect()),
450450
unchecked: false,
451451
},
452452
Test {
453453
name: "push data len 255",
454454
data: vec![0x49; 255],
455-
expected: Ok(once(OpPushData1).chain(once(255)).chain(repeat(0x49).take(255)).collect()),
455+
expected: Ok(once(OpPushData1).chain(once(255)).chain(std::iter::repeat_n(0x49, 255)).collect()),
456456
unchecked: false,
457457
},
458-
// // BIP0062: Pushing 256 to 520 bytes must use OP_PUSHDATA2.
458+
// BIP0062: Pushing 256 to 520 bytes must use OP_PUSHDATA2.
459459
Test {
460460
name: "push data len 256",
461461
data: vec![0x49; 256],
462-
expected: Ok(once(OpPushData2).chain([0, 1]).chain(repeat(0x49).take(256)).collect()),
462+
expected: Ok(once(OpPushData2).chain([0, 1]).chain(std::iter::repeat_n(0x49, 256)).collect()),
463463
unchecked: false,
464464
},
465465
Test {
466466
name: "push data len 520",
467467
data: vec![0x49; 520],
468-
expected: Ok(once(OpPushData2).chain([8, 2]).chain(repeat(0x49).take(520)).collect()),
468+
expected: Ok(once(OpPushData2).chain([8, 2]).chain(std::iter::repeat_n(0x49, 520)).collect()),
469469
unchecked: false,
470470
},
471471
// BIP0062: OP_PUSHDATA4 can never be used, as pushes over 520
@@ -497,14 +497,14 @@ mod tests {
497497
Test {
498498
name: "push data len 32767 (non-canonical)",
499499
data: vec![0x49; 32767],
500-
expected: Ok(once(OpPushData2).chain([255, 127]).chain(repeat(0x49).take(32767)).collect()),
500+
expected: Ok(once(OpPushData2).chain([255, 127]).chain(std::iter::repeat_n(0x49, 32767)).collect()),
501501
unchecked: true,
502502
},
503503
// 5-byte data push via OP_PUSHDATA_4.
504504
Test {
505505
name: "push data len 65536 (non-canonical)",
506506
data: vec![0x49; 65536],
507-
expected: Ok(once(OpPushData4).chain([0, 0, 1, 0]).chain(repeat(0x49).take(65536)).collect()),
507+
expected: Ok(once(OpPushData4).chain([0, 0, 1, 0]).chain(std::iter::repeat_n(0x49, 65536)).collect()),
508508
unchecked: true,
509509
},
510510
];
@@ -549,7 +549,11 @@ mod tests {
549549
value: 0xffeeddccbbaa9988,
550550
expected: vec![OpData8, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff],
551551
},
552-
Test { name: "0xffffffffffffffff", value: u64::MAX, expected: once(OpData8).chain(repeat(0xff).take(8)).collect() },
552+
Test {
553+
name: "0xffffffffffffffff",
554+
value: u64::MAX,
555+
expected: once(OpData8).chain(std::iter::repeat_n(0xff, 8)).collect(),
556+
},
553557
];
554558

555559
for test in tests {

math/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl Uint256 {
8585
#[inline]
8686
/// Computes the target value in float format from BigInt format.
8787
pub fn compact_target_bits(self) -> u32 {
88-
let mut size = (self.bits() + 7) / 8;
88+
let mut size = self.bits().div_ceil(8);
8989
let mut compact = if size <= 3 {
9090
(self.as_u64() << (8 * (3 - size))) as u32
9191
} else {

mining/src/manager.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,15 +1074,14 @@ fn feerate_stats(transactions: Vec<Transaction>, calculated_fees: Vec<u64>) -> O
10741074
mod tests {
10751075
use super::*;
10761076
use spectre_consensus_core::subnets;
1077-
use std::iter::repeat;
10781077

10791078
fn transactions(length: usize) -> Vec<Transaction> {
10801079
let tx = || {
10811080
let tx = Transaction::new(0, vec![], vec![], 0, Default::default(), 0, vec![]);
10821081
tx.set_mass(2);
10831082
tx
10841083
};
1085-
let mut txs = repeat(tx()).take(length).collect_vec();
1084+
let mut txs = std::iter::repeat_n(tx(), length).collect_vec();
10861085
txs[0].subnetwork_id = subnets::SUBNETWORK_ID_COINBASE;
10871086
txs
10881087
}

protocol/p2p/src/core/hub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Hub {
9191
let total_outbound = peers.values().filter(|peer| peer.is_outbound()).count();
9292
let total_inbound = peers.len() - total_outbound;
9393

94-
let mut outbound_count = ((num_peers + 1) / 2).min(total_outbound);
94+
let mut outbound_count = num_peers.div_ceil(2).min(total_outbound);
9595

9696
// If there won't be enough inbound peers to meet the num_peers after we've selected only half for outbound,
9797
// try to require more outbound peers for the difference

rpc/grpc/client/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ impl GrpcClient {
9393
/// `notification_mode` determines how notifications are handled:
9494
///
9595
/// - `MultiListeners` => Multiple listeners are supported via the [`RpcApi`] implementation.
96-
/// Registering listeners is needed before subscribing to notifications.
96+
/// Registering listeners is needed before subscribing to notifications.
9797
/// - `Direct` => A single listener receives the notification via a channel (see `self.notification_channel_receiver()`).
98-
/// Registering a listener is pointless and ignored.
99-
/// Subscribing to notifications ignores the listener ID.
98+
/// Registering a listener is pointless and ignored.
99+
/// Subscribing to notifications ignores the listener ID.
100100
///
101101
/// `url`: the server to connect to
102102
///

rpc/service/src/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ NOTE: This error usually indicates an RPC conversion error between the node and
624624
.get_virtual_chain_accepted_transaction_ids(&session, &virtual_chain_batch, Some(batch_size))
625625
.await?;
626626
// bound added to the length of the accepted transaction ids, which is bounded by merged blocks
627-
virtual_chain_batch.added = virtual_chain_batch.added[..accepted_transaction_ids.len()].to_vec();
627+
virtual_chain_batch.added.truncate(accepted_transaction_ids.len());
628628
accepted_transaction_ids
629629
} else {
630630
vec![]

rpc/wrpc/client/src/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub fn parse_host(input: &str) -> Result<ParseHostOutput, ParseHostError> {
139139
let has_at_least_one_hyphen = host.contains('-');
140140
let hyphens_are_separated_by_valid_chars =
141141
has_at_least_one_hyphen.then(|| host.split('-').all(|part| part.chars().all(|c| c == '.' || c.is_ascii_alphanumeric())));
142-
let tld = host.split('.').last();
142+
let tld = host.split('.').next_back();
143143
// Prevents e.g. numbers being used as TLDs (which in turn prevents e.g. mistakes in IPv4 addresses as being detected as a domain).
144144
let tld_exists_and_is_not_number = tld.map(|tld| tld.parse::<i32>().is_err()).unwrap_or(false);
145145

wallet/core/src/compat/gen0.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn get_v0_parts(data: &str) -> Result<CipherData> {
9292
while !ptr.is_empty() {
9393
let len: usize = ptr[0..5].parse().unwrap();
9494
let mut data = vec![0; len / 2];
95-
hex_decode(ptr[5..(5 + len)].as_bytes(), &mut data).unwrap();
95+
hex_decode(&ptr.as_bytes()[5..(5 + len)], &mut data).unwrap();
9696
list.push(data);
9797
ptr = &ptr[(5 + len)..];
9898
}

wallet/core/src/events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ pub enum EventKind {
290290
impl From<&Events> for EventKind {
291291
fn from(event: &Events) -> Self {
292292
match event {
293-
Events::WalletPing { .. } => EventKind::WalletStart,
293+
Events::WalletPing => EventKind::WalletStart,
294294

295295
Events::Connect { .. } => EventKind::Connect,
296296
Events::Disconnect { .. } => EventKind::Disconnect,

wallet/core/src/utxo/sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ impl SyncMonitor {
9898

9999
async fn handle_event(&self, event: Box<Events>) -> Result<()> {
100100
match *event {
101-
Events::UtxoProcStart { .. } => {}
102-
Events::UtxoProcStop { .. } => {}
101+
Events::UtxoProcStart => {}
102+
Events::UtxoProcStop => {}
103103
_ => {}
104104
}
105105

0 commit comments

Comments
 (0)