Skip to content

Commit

Permalink
Apply lints from rust-1.58 (#1378)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemmih authored Jan 14, 2022
1 parent c06e1d3 commit 7727b33
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 49 deletions.
4 changes: 2 additions & 2 deletions blockchain/chain_sync/src/network_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ where
match self.db.get(&content) {
Ok(Some(b)) => Ok(b),
Ok(None) => Err(format!("Bitswap response successful for: {:?}, but can't find it in the database", content)),
Err(e) => Err(format!("Bitswap response successful for: {:?}, but can't retreive it from the database: {}", content, e.to_string())),
Err(e) => Err(format!("Bitswap response successful for: {:?}, but can't retreive it from the database: {}", content, e)),
}
}
Err(_e) => {
Err(format!("Bitswap get for {:?} timed out", content))
}
Ok(Err(e)) => {
Err(format!("Bitswap get for {:?} failed: {}", content, e.to_string()))
Err(format!("Bitswap get for {:?} failed: {}", content, e))
}
}
}
Expand Down
15 changes: 3 additions & 12 deletions blockchain/chain_sync/src/tipset_syncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1289,10 +1289,7 @@ async fn validate_block<
validations.push(task::spawn_blocking(move || {
let base_fee =
chain::compute_base_fee(v_block_store.as_ref(), &v_base_tipset).map_err(|e| {
TipsetRangeSyncerError::Validation(format!(
"Could not compute base fee: {}",
e.to_string()
))
TipsetRangeSyncerError::Validation(format!("Could not compute base fee: {}", e))
})?;
let parent_base_fee = v_block.header.parent_base_fee();
if &base_fee != parent_base_fee {
Expand Down Expand Up @@ -1581,10 +1578,7 @@ fn verify_winning_post_proof<DB: BlockStore + Send + Sync + 'static, V: ProofVer
Randomness(rand.to_vec()),
)
.map_err(|e| {
TipsetRangeSyncerError::Validation(format!(
"Failed to get sectors for PoSt: {}",
e.to_string()
))
TipsetRangeSyncerError::Validation(format!("Failed to get sectors for PoSt: {}", e))
})?;

V::verify_winning_post(
Expand All @@ -1594,10 +1588,7 @@ fn verify_winning_post_proof<DB: BlockStore + Send + Sync + 'static, V: ProofVer
id,
)
.map_err(|e| {
TipsetRangeSyncerError::Validation(format!(
"Failed to verify winning PoSt: {}",
e.to_string()
))
TipsetRangeSyncerError::Validation(format!("Failed to verify winning PoSt: {}", e))
})
}

Expand Down
2 changes: 1 addition & 1 deletion forest/src/cli/auth_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl AuthCommands {
String::from_utf8(token)
.map_err(|e| handle_rpc_err(e.into()))
.unwrap(),
addr.to_string()
addr
);
}
Err(e) => handle_rpc_err(e),
Expand Down
2 changes: 1 addition & 1 deletion forest/src/cli/genesis_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl GenesisCommands {
let template = GenesisTemplate::new(
network_name
.as_ref()
.unwrap_or(&format!("localnet-{}", Uuid::new_v4().to_string()))
.unwrap_or(&format!("localnet-{}", Uuid::new_v4()))
.to_string(),
);

Expand Down
2 changes: 1 addition & 1 deletion forest/src/cli/net_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl NetCommands {
let addresses: Vec<String> = info
.addrs
.iter()
.map(|addr| format!("{}/p2p/{}", addr.to_string(), info.id.to_string()))
.map(|addr| format!("{}/p2p/{}", addr, info.id))
.collect();

print_stdout(addresses.join("\n"));
Expand Down
8 changes: 4 additions & 4 deletions forest/src/cli/state_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ impl StateCommands {

println!(
"{}({}) / {}({}) ~= {}%",
mp.quality_adj_power.to_string(),
&mp.quality_adj_power,
to_size_string(&mp.quality_adj_power),
tp.quality_adj_power.to_string(),
&tp.quality_adj_power,
to_size_string(&tp.quality_adj_power),
(mp.quality_adj_power * 100) / tp.quality_adj_power
(&mp.quality_adj_power * 100) / &tp.quality_adj_power
);
}
Self::GetActor { address } => {
Expand Down Expand Up @@ -138,7 +138,7 @@ impl StateCommands {

for a in actors {
let AddressJson(addr) = a;
println!("{}", addr.to_string());
println!("{}", addr);
}
}
Self::Lookup { reverse, address } => {
Expand Down
2 changes: 1 addition & 1 deletion forest/src/cli/sync_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl SyncCommands {
println!("Base:\t{}", base_cids);
println!("Target:\t{} ({})", target_cids, target_height);
println!("Height diff:\t{}", height_diff.abs());
println!("Stage:\t{}", state.stage().to_string());
println!("Stage:\t{}", state.stage());
println!("Height:\t{}", state.epoch());

if let Some(duration) = elapsed_time {
Expand Down
14 changes: 7 additions & 7 deletions key_management/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Wallet {
if let Some(k) = self.keys.get(addr) {
return Ok(k.clone());
}
let key_string = format!("wallet-{}", addr.to_string());
let key_string = format!("wallet-{}", addr);
let key_info = match self.keystore.get(&key_string) {
Ok(k) => k,
Err(_) => {
Expand Down Expand Up @@ -99,7 +99,7 @@ impl Wallet {
/// Add Key_Info to the Wallet, return the Address that resolves to this newly added KeyInfo
pub fn import(&mut self, key_info: KeyInfo) -> Result<Address, Error> {
let k = Key::try_from(key_info)?;
let addr = format!("wallet-{}", k.address.to_string());
let addr = format!("wallet-{}", k.address);
self.keystore.put(addr, k.key_info)?;
Ok(k.address)
}
Expand All @@ -118,7 +118,7 @@ impl Wallet {

/// Set a default KeyInfo to the Wallet
pub fn set_default(&mut self, addr: Address) -> Result<(), Error> {
let addr_string = format!("wallet-{}", addr.to_string());
let addr_string = format!("wallet-{}", addr);
let key_info = self.keystore.get(&addr_string)?;
if self.keystore.get("default").is_ok() {
self.keystore.remove("default".to_string())?; // This line should unregister current default key then continue
Expand All @@ -130,7 +130,7 @@ impl Wallet {
/// Generate a new Address that fits the requirement of the given SignatureType
pub fn generate_addr(&mut self, typ: SignatureType) -> Result<Address, Error> {
let key = generate_key(typ)?;
let addr = format!("wallet-{}", key.address.to_string());
let addr = format!("wallet-{}", key.address);
self.keystore.put(addr, key.key_info.clone())?;
self.keys.insert(key.address, key.clone());
let value = self.keystore.get(&"default".to_string());
Expand Down Expand Up @@ -174,14 +174,14 @@ pub fn list_addrs(keystore: &KeyStore) -> Result<Vec<Address>, Error> {

/// Return Key corresponding to given Address in KeyStore
pub fn find_key(addr: &Address, keystore: &KeyStore) -> Result<Key, Error> {
let key_string = format!("wallet-{}", addr.to_string());
let key_string = format!("wallet-{}", addr);
let key_info = keystore.get(&key_string)?;
let new_key = Key::try_from(key_info)?;
Ok(new_key)
}

pub fn try_find(addr: &Address, keystore: &mut KeyStore) -> Result<KeyInfo, Error> {
let key_string = format!("wallet-{}", addr.to_string());
let key_string = format!("wallet-{}", addr);
match keystore.get(&key_string) {
Ok(k) => Ok(k),
Err(_) => {
Expand Down Expand Up @@ -216,7 +216,7 @@ pub fn generate_key(typ: SignatureType) -> Result<Key, Error> {
/// Import KeyInfo into KeyStore
pub fn import(key_info: KeyInfo, keystore: &mut KeyStore) -> Result<Address, Error> {
let k = Key::try_from(key_info)?;
let addr = format!("wallet-{}", k.address.to_string());
let addr = format!("wallet-{}", k.address);
keystore.put(addr, k.key_info)?;
Ok(k.address)
}
Expand Down
4 changes: 2 additions & 2 deletions node/rpc/src/wallet_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ where

let key = Key::try_from(key_info)?;

let addr = format!("wallet-{}", key.address.to_string());
let addr = format!("wallet-{}", key.address);

let mut keystore = data.keystore.write().await;

Expand Down Expand Up @@ -165,7 +165,7 @@ where
let mut keystore = data.keystore.write().await;
let key = wallet::generate_key(sig_raw.0)?;

let addr = format!("wallet-{}", key.address.to_string());
let addr = format!("wallet-{}", key.address);
keystore.put(addr, key.key_info.clone())?;
let value = keystore.get(&"default".to_string());
if value.is_err() {
Expand Down
4 changes: 2 additions & 2 deletions vm/address/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,14 @@ fn encode(addr: &Address) -> String {
format!(
"{}{}{}",
addr.network.to_prefix(),
addr.protocol().to_string(),
addr.protocol(),
ADDRESS_ENCODER.encode(bz.as_mut()),
)
}
Protocol::ID => format!(
"{}{}{}",
addr.network.to_prefix(),
addr.protocol().to_string(),
addr.protocol(),
from_leb_bytes(&addr.payload_bytes()).expect("should read encoded bytes"),
),
}
Expand Down
4 changes: 1 addition & 3 deletions vm/state_migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ impl<BS: BlockStore + Send + Sync> MigrationJob<BS> {
.map_err(|e| {
MigrationError::MigrationJobRun(format!(
"state migration failed for {} actor, addr {}:{}",
self.actor_state.code,
self.address,
e.to_string()
self.actor_state.code, self.address, e
))
})?;

Expand Down
18 changes: 5 additions & 13 deletions vm/state_tree/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ where
) -> Result<Cid, String> {
let state_root = forest_car::load_car(store, reader)
.await
.map_err(|e| format!("Import StateTree failed: {}", e.to_string()))?;
.map_err(|e| format!("Import StateTree failed: {}", e))?;
if state_root.len() != 1 {
return Err(format!(
"Import StateTree failed: expected root length of 1, got: {}",
Expand All @@ -244,12 +244,8 @@ where
let state_root = state_root[0];

// Attempt to load StateTree to see if the root CID indeed points to a valid StateTree
StateTree::new_from_root(store, &state_root).map_err(|e| {
format!(
"Import StateTree failed: Invalid StateTree root: {}",
e.to_string()
)
})?;
StateTree::new_from_root(store, &state_root)
.map_err(|e| format!("Import StateTree failed: Invalid StateTree root: {}", e))?;

Ok(state_root)
}
Expand Down Expand Up @@ -454,12 +450,8 @@ where
task::spawn(async move { header.write_stream_async(&mut writer, &mut rx).await });

// Check if given Cid is a StateTree
StateTree::new_from_root(bs, &state_root).map_err(|e| {
format!(
"Export StateTree failed: Invalid StateTree root: {}",
e.to_string()
)
})?;
StateTree::new_from_root(bs, &state_root)
.map_err(|e| format!("Export StateTree failed: Invalid StateTree root: {}", e))?;

// Recurse over the StateTree links
let mut seen = Default::default();
Expand Down

0 comments on commit 7727b33

Please sign in to comment.