Skip to content

Commit

Permalink
Fix clippy warnings as of Rust 1.67 (#3042)
Browse files Browse the repository at this point in the history
* Fix clippy warnings emitted as of Rust 1.67

* Remove useless use of `format!` in `Output::error`
  • Loading branch information
romac authored Jan 27, 2023
1 parent 41d2fc0 commit 097c5df
Show file tree
Hide file tree
Showing 87 changed files with 244 additions and 309 deletions.
2 changes: 1 addition & 1 deletion crates/relayer-cli/src/chain_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub async fn get_configs(
for i in 0..n {
for chain_j in &chains[i + 1..] {
let chain_i = &chains[i];
let resource = format!("{}-{}.json", chain_i, chain_j).to_string();
let resource = format!("{chain_i}-{chain_j}.json").to_string();
let commit_clone = commit.clone();
path_handles.push(tokio::spawn(async move {
IBCPath::fetch(resource, commit_clone).await
Expand Down
8 changes: 4 additions & 4 deletions crates/relayer-cli/src/commands/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Runnable for ClearPacketsCmd {
&self.channel_id,
) {
Ok((chains, _)) => chains,
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
};

// If `counterparty_key_name` is provided, fetch the counterparty chain's
Expand All @@ -104,7 +104,7 @@ impl Runnable for ClearPacketsCmd {
Ok(mut dst_chain_cfg) => {
dst_chain_cfg.key_name = counterparty_key_name.to_string();
}
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}

Expand All @@ -118,11 +118,11 @@ impl Runnable for ClearPacketsCmd {
let fwd_link = match Link::new_from_opts(chains.src.clone(), chains.dst, opts, false, false)
{
Ok(link) => link,
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
};
let rev_link = match fwd_link.reverse(false, false) {
Ok(link) => link,
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
};

// Schedule RecvPacket messages for pending packets in both directions.
Expand Down
9 changes: 4 additions & 5 deletions crates/relayer-cli/src/commands/config/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ impl Runnable for ValidateCmd {
Output::error("the configuration file is empty").exit();
}
}
Err(e) => Output::error(format!(
"error reading the configuration file {:?}: {}",
p, e
))
.exit(),
Err(e) => {
Output::error(format!("error reading the configuration file {p:?}: {e}"))
.exit()
}
}
}
None => Output::error("no configuration file found").exit(),
Expand Down
3 changes: 1 addition & 2 deletions crates/relayer-cli/src/commands/create/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ impl Runnable for CreateChannelCommand {
}
Err(e) => {
Output::error(format!(
"An error occurred while waiting for user input: {}",
e
"An error occurred while waiting for user input: {e}"
));
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/relayer-cli/src/commands/create/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl CreateConnectionCommand {
let delay = Duration::from_secs(self.delay);
match Connection::new(client_a, client_b, delay) {
Ok(conn) => Output::success(conn).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}

Expand All @@ -112,7 +112,7 @@ impl CreateConnectionCommand {
// Validate & spawn runtime for chain_a.
let chain_a = match spawn_chain_runtime(&config, &self.chain_a_id) {
Ok(handle) => handle,
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
};

// Unwrap the identifier of the client on chain_a.
Expand Down Expand Up @@ -143,7 +143,7 @@ impl CreateConnectionCommand {
// Validate & spawn runtime for chain_b.
let chain_b = match spawn_chain_runtime(&config, &chain_b_id) {
Ok(handle) => handle,
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
};

// Unwrap the identifier of the client on chain_b.
Expand All @@ -170,7 +170,7 @@ impl CreateConnectionCommand {
let delay = Duration::from_secs(self.delay);
match Connection::new(client_a, client_b, delay) {
Ok(conn) => Output::success(conn).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-cli/src/commands/fee/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn fee_transfer(chains: ChainHandlePair, opts: FeeTransferOptions) -> Result<(),

match res {
Ok(ev) => Output::success(ev).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-cli/src/commands/keys/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ fn check_key_exists<S: SigningKeyPairSized>(keyring: &KeyRing<S>, key_name: &str
if overwrite {
warn!("key {} will be overwritten", key_name);
} else {
Output::error(format!("A key with name '{}' already exists", key_name)).exit();
Output::error(format!("A key with name '{key_name}' already exists")).exit();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/relayer-cli/src/commands/keys/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn get_balance(chain: impl ChainHandle, key_name: Option<String>, denom: Option<
))
.exit()
}
Err(e) => Output::error(format!("there was a problem querying the balance: {}", e)).exit(),
Err(e) => Output::error(format!("there was a problem querying the balance: {e}")).exit(),
}
}

Expand All @@ -98,15 +98,15 @@ fn get_balances(chain: impl ChainHandle, key_name: Option<String>) {
chain_config.key_name
});

let mut pretty_output = format!("Balances for key `{}`:", key_name);
let mut pretty_output = format!("Balances for key `{key_name}`:");
for balance in balances {
write!(pretty_output, "\n\t{} {}", balance.amount, balance.denom)
.unwrap_or_else(exit_with_unrecoverable_error);
}

Output::success_msg(pretty_output).exit()
}
Err(e) => Output::error(format!("there was a problem querying the balance: {}", e)).exit(),
Err(e) => Output::error(format!("there was a problem querying the balance: {e}")).exit(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/relayer-cli/src/commands/keys/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ impl Runnable for KeysDeleteCmd {
Output::success_msg(format!("Removed all keys on chain {}", opts.config.id))
.exit()
}
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
},
KeysDeleteId::Named(key_name) => match delete_key(&opts.config, key_name) {
Ok(_) => Output::success_msg(format!(
"Removed key ({}) on chain {}",
key_name, opts.config.id
))
.exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-cli/src/commands/listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl FromStr for EventFilter {
match s {
"NewBlock" => Ok(Self::NewBlock),
"Tx" => Ok(Self::Tx),
invalid => Err(format!("unrecognized event type: {}", invalid).into()),
invalid => Err(format!("unrecognized event type: {invalid}").into()),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-cli/src/commands/misbehaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Runnable for MisbehaviourCmd {
let res = monitor_misbehaviour(&self.chain_id, &self.client_id, &config);
match res {
Ok(some_event) => Output::success(some_event).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-cli/src/commands/query/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Runnable for QueryChannelEndCmd {
Output::success(channel_end).exit()
}
}
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-cli/src/commands/query/channel_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Runnable for QueryChannelClientCmd {
channel_id: self.channel_id.clone(),
}) {
Ok(cs) => Output::success(cs).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-cli/src/commands/query/channel_ends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl Runnable for QueryChannelEndsCmd {
fn run(&self) {
match do_run::<BaseChainHandle>(self) {
Ok(()) => {}
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/relayer-cli/src/commands/query/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl Runnable for QueryChannelsCmd {
fn run(&self) {
match run_query_channels::<BaseChainHandle>(self) {
Ok(output) => Output::success(output).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}
}
Expand Down Expand Up @@ -355,8 +355,8 @@ impl QueryChannelsOutput {
impl Debug for QueryChannelsOutput {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
match self {
QueryChannelsOutput::Verbose(output) => write!(f, "{:#?}", output),
QueryChannelsOutput::Summary(output) => write!(f, "{:#?}", output),
QueryChannelsOutput::Verbose(output) => write!(f, "{output:#?}"),
QueryChannelsOutput::Summary(output) => write!(f, "{output:#?}"),
QueryChannelsOutput::Pretty(output) => {
output.iter().try_for_each(|pretty_print| {
write!(
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-cli/src/commands/query/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Runnable for QueryAllClientsCmd {
}
}
}
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/relayer-cli/src/commands/query/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Runnable for QueryConnectionEndCmd {
Output::success(connection_end).exit()
}
}
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ impl Runnable for QueryConnectionChannelsCmd {
.collect();
Output::success(ids).exit()
}
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/relayer-cli/src/commands/query/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ impl Runnable for QueryConnectionsCmd {
}
}
Err(e) => Output::error(format!(
"An error occurred trying to query connections: {}",
e
"An error occurred trying to query connections: {e}"
))
.exit(),
};
Expand Down
4 changes: 2 additions & 2 deletions crates/relayer-cli/src/commands/query/packet/ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl QueryPacketAcknowledgmentCmd {
.map(|(bytes, _)| {
Hex::upper_case()
.encode_to_string(bytes.clone())
.unwrap_or_else(|_| format!("{:?}", bytes))
.unwrap_or_else(|_| format!("{bytes:?}"))
})
}
}
Expand All @@ -95,7 +95,7 @@ impl Runnable for QueryPacketAcknowledgmentCmd {
fn run(&self) {
match self.execute() {
Ok(hex) => Output::success(hex).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-cli/src/commands/query/packet/acks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Runnable for QueryPacketAcknowledgementsCmd {
match self.execute() {
Ok(p) if json() => Output::success(p).exit(),
Ok(p) => Output::success(p.collated()).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/relayer-cli/src/commands/query/packet/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl QueryPacketCommitmentCmd {
} else {
Ok(Hex::upper_case()
.encode_to_string(bytes.clone())
.unwrap_or_else(|_| format!("{:?}", bytes)))
.unwrap_or_else(|_| format!("{bytes:?}")))
}
}
}
Expand All @@ -105,7 +105,7 @@ impl Runnable for QueryPacketCommitmentCmd {
fn run(&self) {
match self.execute() {
Ok(hex) => Output::success(hex).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Runnable for QueryPacketCommitmentsCmd {
match self.execute() {
Ok(p) if json() => Output::success(p).exit(),
Ok(p) => Output::success(p.collated()).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ impl Runnable for DenomTraceCmd {
))
.exit(),
Err(e) => Output::error(format!(
"there was a problem querying the denomination trace: {}",
e
"there was a problem querying the denomination trace: {e}"
))
.exit(),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-cli/src/commands/query/tx/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Runnable for QueryTxEventsCmd {

match res {
Ok(res) => Output::success(res).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/relayer-cli/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Runnable for StartCmd {

let supervisor_handle = make_supervisor::<CachingChainHandle>(config, self.full_scan)
.unwrap_or_else(|e| {
Output::error(format!("Hermes failed to start, last error: {}", e)).exit()
Output::error(format!("Hermes failed to start, last error: {e}")).exit()
});

match crate::config::config_path() {
Expand Down Expand Up @@ -81,7 +81,7 @@ fn register_signals(tx_cmd: Sender<SupervisorCmd>) -> Result<(), io::Error> {
if let Ok(state) = rx.recv() {
if json() {
match serde_json::to_string(&state) {
Ok(out) => println!("{}", out),
Ok(out) => println!("{out}"),
Err(e) => {
error!("failed to serialize relayer state to JSON: {}", e)
}
Expand Down
6 changes: 3 additions & 3 deletions crates/relayer-cli/src/commands/tx/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl Runnable for TxChanOpenInitCmd {

let chains = match ChainHandlePair::spawn(&config, &self.src_chain_id, &self.dst_chain_id) {
Ok(chains) => chains,
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
};

// Retrieve the connection
Expand All @@ -126,7 +126,7 @@ impl Runnable for TxChanOpenInitCmd {
IncludeProof::No,
) {
Ok((connection, _)) => connection,
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
};

let channel = Channel {
Expand Down Expand Up @@ -158,7 +158,7 @@ impl Runnable for TxChanOpenInitCmd {

match res {
Ok(receipt) => Output::success(receipt).exit(),
Err(e) => Output::error(format!("{}", e)).exit(),
Err(e) => Output::error(e).exit(),
}
}
}
Expand Down
Loading

0 comments on commit 097c5df

Please sign in to comment.