Skip to content

Commit 9168119

Browse files
committed
chore: adapt codebase to Rust 1.86
1 parent 11ef5f7 commit 9168119

File tree

16 files changed

+73
-93
lines changed

16 files changed

+73
-93
lines changed

bridges/centralized-ethereum/src/actors/dr_reporter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ impl Handler<DrReporterMsg> for DrReporter {
311311
// Error in call_with_confirmations
312312
log::error!(
313313
"{}: {:?}",
314-
format!("Cannot call reportResultBatch{:?}", &batched_report),
314+
format_args!("Cannot call reportResultBatch{:?}", &batched_report),
315315
e
316316
);
317317
}

bridges/centralized-ethereum/src/actors/eth_poller.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl EthPoller {
193193
"Fail to get status of queries #{} to #{}: {}",
194194
init_index,
195195
next_dr_id,
196-
queries_status.unwrap_err().to_string()
196+
queries_status.unwrap_err()
197197
);
198198
}
199199
}

bridges/centralized-ethereum/src/actors/watch_dog.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,7 @@ async fn fetch_wit_info(
441441
let req = jsonrpc::Request::method("getPkh").timeout(Duration::from_secs(5));
442442
let res = wit_client.send(req).await;
443443
let wit_account = match res {
444-
Ok(Ok(res)) => match serde_json::from_value::<String>(res) {
445-
Ok(pkh) => Some(pkh),
446-
Err(_) => None,
447-
},
444+
Ok(Ok(res)) => serde_json::from_value::<String>(res).ok(),
448445
Ok(Err(_)) => None,
449446
Err(err) => {
450447
log::debug!("fetch_wit_info => method: getPkh; error: {}", err);

crypto/src/merkle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn merkle_tree_root_with_hashing_function<T: Copy>(hash_concat: fn(T, T) -> T, h
4747
n => {
4848
// n nodes: split into 2 and calculate the root for each half
4949
// split at the first power of two greater or equal to n / 2
50-
let (left, right) = hashes.split_at(((n + 1) / 2).next_power_of_two());
50+
let (left, right) = hashes.split_at(n.div_ceil(2).next_power_of_two());
5151
let left_hash = merkle_tree_root_with_hashing_function(hash_concat, left);
5252
let right_hash = merkle_tree_root_with_hashing_function(hash_concat, right);
5353

data_structures/benches/sort_active_identities.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,18 @@ where
105105
}
106106

107107
fn staggered(take: usize) -> impl Iterator<Item = u32> {
108-
iter::repeat(10000)
109-
.take(take)
110-
.chain(iter::repeat(1000).take(take))
111-
.chain(iter::repeat(100).take(take))
112-
.chain(iter::repeat(10).take(take))
108+
iter::repeat_n(10000, take)
109+
.chain(iter::repeat_n(1000, take))
110+
.chain(iter::repeat_n(100, take))
111+
.chain(iter::repeat_n(10, take))
113112
}
114113

115114
fn all_unique(n: u32) -> impl Iterator<Item = u32> {
116115
1..=n
117116
}
118117

119118
fn all_equal(n: usize) -> impl Iterator<Item = u32> {
120-
iter::repeat(1).take(n)
119+
iter::repeat_n(1, n)
121120
}
122121

123122
fn b_staggered_10000(b: &mut Bencher) {

data_structures/src/radon_report.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,10 @@ where
239239
///
240240
/// * `subscript_index` is used to distinguish the different subscripts in one RADON script.
241241
/// * `operator_index` is the index of the operator inside the subscript: the partial result.
242-
/// The first element is always the input value, and the last element is the result of the
243-
/// subscript.
242+
/// The first element is always the input value, and the last element is the result of the
243+
/// subscript.
244244
/// * `element_index` is the index of the element inside the array that serves as the input of
245-
/// the subscript.
245+
/// the subscript.
246246
pub subscript_partial_results: Vec<Vec<Vec<RT>>>,
247247
}
248248

net/src/client/http/mod.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,30 +105,28 @@ impl WitnetHttpClient {
105105
reqwest::redirect::Policy::none()
106106
};
107107

108-
let client;
109-
match proxy {
108+
let client = match proxy {
110109
Some(proxy) => {
111110
let proxy = reqwest::Proxy::http(proxy).map_err(|err| {
112111
WitnetHttpError::ClientBuildError {
113112
msg: err.to_string(),
114113
}
115114
})?;
116-
client = reqwest::Client::builder()
115+
116+
reqwest::Client::builder()
117117
.proxy(proxy)
118118
.redirect(redirect_policy)
119119
.build()
120120
.map_err(|err| WitnetHttpError::ClientBuildError {
121121
msg: err.to_string(),
122-
})?;
123-
}
124-
None => {
125-
client = reqwest::Client::builder()
126-
.redirect(redirect_policy)
127-
.build()
128-
.map_err(|err| WitnetHttpError::ClientBuildError {
129-
msg: err.to_string(),
130-
})?;
122+
})?
131123
}
124+
None => reqwest::Client::builder()
125+
.redirect(redirect_policy)
126+
.build()
127+
.map_err(|err| WitnetHttpError::ClientBuildError {
128+
msg: err.to_string(),
129+
})?,
132130
};
133131

134132
Ok(Self { client })

node/src/actors/chain_manager/handlers.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use witnet_data_structures::{
2121
proto::versioning::ProtocolVersion,
2222
refresh_protocol_version,
2323
staking::{
24-
errors::StakesError,
2524
prelude::{Power, StakeKey},
2625
stakes::QueryStakesKey,
2726
},
@@ -861,7 +860,7 @@ impl PeersBeacons {
861860
b.as_ref()
862861
.map(|last_beacon| last_beacon.highest_superblock_checkpoint)
863862
})
864-
.chain(std::iter::repeat(None).take(num_missing_peers)),
863+
.chain(std::iter::repeat_n(None, num_missing_peers)),
865864
consensus_threshold,
866865
)
867866
// Flatten result:
@@ -1023,7 +1022,7 @@ impl Handler<PeersBeacons> for ChainManager {
10231022
let peers_needed_for_consensus = outbound_limit
10241023
.map(|x| {
10251024
// ceil(x * consensus_threshold / 100)
1026-
(usize::from(x) * consensus_threshold + 99) / 100
1025+
(usize::from(x) * consensus_threshold).div_ceil(100)
10271026
})
10281027
.unwrap_or(1);
10291028

@@ -1553,11 +1552,7 @@ impl Handler<QueryStakes> for ChainManager {
15531552
let limit = params.limit.unwrap_or(u16::MAX) as usize;
15541553

15551554
// fetch filtered stake entries from current chain state:
1556-
let mut stakes = self
1557-
.chain_state
1558-
.stakes
1559-
.query_stakes(filter.clone())
1560-
.map_err(StakesError::from)?;
1555+
let mut stakes = self.chain_state.stakes.query_stakes(filter.clone())?;
15611556

15621557
// filter out stake entries having a nonce, last mining or witnessing epochs (depending
15631558
// on actual ordering field) older than calculated `since_epoch`:

rad/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,6 @@ pub mod fromx {
875875
mod tests {
876876
use std::convert::TryFrom;
877877

878-
use tokio;
879-
880878
use serde_cbor::Value;
881879
use witnet_data_structures::{
882880
chain::RADFilter,
@@ -1985,11 +1983,7 @@ mod tests {
19851983
});
19861984
}
19871985
Err(e) => {
1988-
println!(
1989-
"Encountered error for proxy {:?}: {}",
1990-
transport,
1991-
e.to_string()
1992-
);
1986+
println!("Encountered error for proxy {:?}: {}", transport, e);
19931987
}
19941988
}
19951989
}

rad/src/types/boolean.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ impl Operable for RadonBoolean {
8080
match call {
8181
(RadonOpCodes::Identity, None) => identity(RadonTypes::from(self.clone())),
8282
(RadonOpCodes::BooleanNegate, None) => Ok(boolean_operators::negate(self).into()),
83-
(RadonOpCodes::BooleanAsString, None) => boolean_operators::to_string(self.clone())
84-
.map(RadonTypes::from)
85-
.map_err(Into::into),
83+
(RadonOpCodes::BooleanAsString, None) => {
84+
boolean_operators::to_string(self.clone()).map(RadonTypes::from)
85+
}
8686
(op_code, args) => Err(RadError::UnsupportedOperator {
8787
input_type: RADON_BOOLEAN_TYPE_NAME.to_string(),
8888
operator: op_code.to_string(),

0 commit comments

Comments
 (0)