Skip to content

Commit

Permalink
Update all crates to Rust edition 2021 and fix clippy warnings introd…
Browse files Browse the repository at this point in the history
…uced in Rust 1.67 (#1261)

* Fix clippy warnings as of Rust 1.67

* Update all crates to Rust 2021
  • Loading branch information
romac authored Jan 30, 2023
1 parent 95e4505 commit 3c79d14
Show file tree
Hide file tree
Showing 71 changed files with 235 additions and 281 deletions.
3 changes: 3 additions & 0 deletions .changelog/unreleased/improvements/1262-edition-2021.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Update all crates to the [2021 edition](https://doc.rust-
lang.org/edition-guide/rust-2021/index.html) of the Rust language
([#1262](https://github.com/informalsystems/tendermint-rs/issues/1262))
2 changes: 1 addition & 1 deletion abci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "tendermint-abci"
version = "0.28.0"
authors = ["Informal Systems <hello@informal.systems>"]
edition = "2018"
edition = "2021"
license = "Apache-2.0"
readme = "README.md"
categories = ["cryptography::cryptocurrencies", "network-programming"]
Expand Down
4 changes: 2 additions & 2 deletions abci/src/application/kvstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl Application for KeyValueStoreApp {
fn query(&self, request: RequestQuery) -> ResponseQuery {
let key = match std::str::from_utf8(&request.data) {
Ok(s) => s,
Err(e) => panic!("Failed to intepret key as UTF-8: {}", e),
Err(e) => panic!("Failed to intepret key as UTF-8: {e}"),
};
debug!("Attempting to get key: {}", key);
match self.get(key) {
Expand Down Expand Up @@ -161,7 +161,7 @@ impl Application for KeyValueStoreApp {
codespace: "".to_string(),
},
},
Err(e) => panic!("Failed to get key \"{}\": {:?}", key, e),
Err(e) => panic!("Failed to get key \"{key}\": {e:?}"),
}
}

Expand Down
4 changes: 2 additions & 2 deletions config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "tendermint-config"
version = "0.28.0" # Also update `html_root_url` in lib.rs and
# depending crates (rpc, light-node, ..) when bumping this
# depending crates (rpc, light-node, ..) when bumping this
license = "Apache-2.0"
homepage = "https://www.tendermint.com/"
repository = "https://github.com/informalsystems/tendermint-rs/tree/main/tendermint"
readme = "../README.md"
categories = ["cryptography", "cryptography::cryptocurrencies", "database"]
keywords = ["blockchain", "bft", "consensus", "cosmos", "tendermint"]
edition = "2018"
edition = "2021"

description = """
tendermint-config provides functions for loading and validating Tendermint
Expand Down
18 changes: 7 additions & 11 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,15 @@ impl FromStr for LogLevel {
global = Some(parts[0].to_owned());
continue;
} else if parts.len() != 2 {
return Err(Error::parse(format!("error parsing log level: {}", level)));
return Err(Error::parse(format!("error parsing log level: {level}")));
}

let key = parts[0].to_owned();
let value = parts[1].to_owned();

if components.insert(key, value).is_some() {
return Err(Error::parse(format!(
"duplicate log level setting for: {}",
level
"duplicate log level setting for: {level}"
)));
}
}
Expand All @@ -229,13 +228,13 @@ impl FromStr for LogLevel {
impl fmt::Display for LogLevel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(global) = &self.global {
write!(f, "{}", global)?;
write!(f, "{global}")?;
if !self.components.is_empty() {
write!(f, ",")?;
}
}
for (i, (k, v)) in self.components.iter().enumerate() {
write!(f, "{}:{}", k, v)?;
write!(f, "{k}:{v}")?;

if i < self.components.len() - 1 {
write!(f, ",")?;
Expand All @@ -249,7 +248,7 @@ impl fmt::Display for LogLevel {
impl<'de> Deserialize<'de> for LogLevel {
fn deserialize<D: de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let levels = String::deserialize(deserializer)?;
Self::from_str(&levels).map_err(|e| D::Error::custom(format!("{}", e)))
Self::from_str(&levels).map_err(|e| D::Error::custom(format!("{e}")))
}
}

Expand Down Expand Up @@ -725,7 +724,7 @@ where
string
.parse()
.map(Some)
.map_err(|e| D::Error::custom(format!("{}", e)))
.map_err(|e| D::Error::custom(format!("{e}")))
}

fn serialize_optional_value<S, T>(value: &Option<T>, serializer: S) -> Result<S::Ok, S::Error>
Expand Down Expand Up @@ -754,10 +753,7 @@ where
}

for item in string.split(',') {
result.push(
item.parse()
.map_err(|e| D::Error::custom(format!("{}", e)))?,
);
result.push(item.parse().map_err(|e| D::Error::custom(format!("{e}")))?);
}

Ok(result)
Expand Down
26 changes: 13 additions & 13 deletions config/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ impl Address {
if raw_address.starts_with("tcp://") {
raw_address.parse().ok()
} else {
format!("tcp://{}", raw_address).parse().ok()
format!("tcp://{raw_address}").parse().ok()
}
}
}

impl<'de> Deserialize<'de> for Address {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::from_str(&String::deserialize(deserializer)?)
.map_err(|e| D::Error::custom(format!("{}", e)))
.map_err(|e| D::Error::custom(format!("{e}")))
}
}

Expand All @@ -72,13 +72,13 @@ impl Display for Address {
peer_id: None,
host,
port,
} => write!(f, "{}{}:{}", TCP_PREFIX, host, port),
} => write!(f, "{TCP_PREFIX}{host}:{port}"),
Address::Tcp {
peer_id: Some(peer_id),
host,
port,
} => write!(f, "{}{}@{}:{}", TCP_PREFIX, peer_id, host, port),
Address::Unix { path } => write!(f, "{}{}", UNIX_PREFIX, path),
} => write!(f, "{TCP_PREFIX}{peer_id}@{host}:{port}"),
Address::Unix { path } => write!(f, "{UNIX_PREFIX}{path}"),
}
}
}
Expand All @@ -98,7 +98,7 @@ impl FromStr for Address {
addr.to_owned()
} else {
// If the address has no scheme, assume it's TCP
format!("{}{}", TCP_PREFIX, addr)
format!("{TCP_PREFIX}{addr}")
};
let url = Url::parse(&prefixed_addr).map_err(Error::parse_url)?;
match url.scheme() {
Expand All @@ -112,17 +112,17 @@ impl FromStr for Address {
host: url
.host_str()
.ok_or_else(|| {
Error::parse(format!("invalid TCP address (missing host): {}", addr))
Error::parse(format!("invalid TCP address (missing host): {addr}"))
})?
.to_owned(),
port: url.port().ok_or_else(|| {
Error::parse(format!("invalid TCP address (missing port): {}", addr))
Error::parse(format!("invalid TCP address (missing port): {addr}"))
})?,
}),
"unix" => Ok(Self::Unix {
path: url.path().to_string(),
}),
_ => Err(Error::parse(format!("invalid address scheme: {:?}", addr))),
_ => Err(Error::parse(format!("invalid address scheme: {addr:?}"))),
}
}
}
Expand Down Expand Up @@ -166,7 +166,7 @@ mod tests {
assert_eq!(host, "35.192.61.41");
assert_eq!(port, 26656);
},
other => panic!("unexpected address type: {:?}", other),
other => panic!("unexpected address type: {other:?}"),
}
}
}
Expand All @@ -188,7 +188,7 @@ mod tests {
assert_eq!(host, "35.192.61.41");
assert_eq!(*port, 26656);
},
other => panic!("unexpected address type: {:?}", other),
other => panic!("unexpected address type: {other:?}"),
}
}
}
Expand All @@ -200,7 +200,7 @@ mod tests {
Address::Unix { path } => {
assert_eq!(path, "/tmp/node.sock");
},
other => panic!("unexpected address type: {:?}", other),
other => panic!("unexpected address type: {other:?}"),
}
}

Expand All @@ -227,7 +227,7 @@ mod tests {
assert_eq!(host, "[2001:0:3238:dfe1:63::fefb]");
assert_eq!(*port, 26656);
},
other => panic!("unexpected address type: {:?}", other),
other => panic!("unexpected address type: {other:?}"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion light-client-js/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "tendermint-light-client-js"
version = "0.28.0"
authors = ["Informal Systems <hello@informal.systems>"]
edition = "2018"
edition = "2021"
license = "Apache-2.0"
readme = "README.md"
keywords = ["blockchain", "bft", "consensus", "light-client", "tendermint"]
Expand Down
2 changes: 1 addition & 1 deletion light-client-verifier/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::types::TrustThreshold;

/// Verification parameters
#[derive(Copy, Clone, Debug, PartialEq, Eq, Display, Serialize, Deserialize)]
#[display(fmt = "{:?}", self)]
#[display(fmt = "{self:?}")]
pub struct Options {
/// Defines what fraction of the total voting power of a known
/// and trusted validator set is sufficient for a commit to be
Expand Down
4 changes: 2 additions & 2 deletions light-client-verifier/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<'a> UntrustedBlockState<'a> {
/// A light block is the core data structure used by the light client.
/// It records everything the light client needs to know about a block.
#[derive(Clone, Debug, Display, PartialEq, Eq, Serialize, Deserialize)]
#[display(fmt = "{:?}", self)]
#[display(fmt = "{self:?}")]
pub struct LightBlock {
/// Header and commit of this block
pub signed_header: SignedHeader,
Expand Down Expand Up @@ -167,7 +167,7 @@ impl LightBlock {
/// Contains the local status information, like the latest height, latest block and valset hashes,
/// list of of connected full nodes (primary and witnesses).
#[derive(Clone, Debug, Display, PartialEq, Eq, Serialize, Deserialize)]
#[display(fmt = "{:?}", self)]
#[display(fmt = "{self:?}")]
pub struct LatestStatus {
/// The latest height we are trusting.
pub height: Option<u64>,
Expand Down
2 changes: 1 addition & 1 deletion light-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tendermint-light-client"
version = "0.28.0"
edition = "2018"
edition = "2021"
license = "Apache-2.0"
readme = "README.md"
keywords = ["blockchain", "bft", "consensus", "cosmos", "tendermint"]
Expand Down
4 changes: 2 additions & 2 deletions light-client/examples/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn main() {
std::process::exit(1);
},
Some(Command::Sync(sync_opts)) => sync_cmd(sync_opts).unwrap_or_else(|e| {
eprintln!("Command failed: {}", e);
eprintln!("Command failed: {e}");
std::process::exit(1);
}),
}
Expand Down Expand Up @@ -125,7 +125,7 @@ fn sync_cmd(opts: SyncOpts) -> Result<(), Box<dyn std::error::Error>> {
println!("[info] synced to block {}", light_block.height());
},
Err(err) => {
println!("[error] sync failed: {}", err);
println!("[error] sync failed: {err}");
},
}

Expand Down
2 changes: 0 additions & 2 deletions light-client/src/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,6 @@ impl LightClient {
target_height: Height,
state: &mut State,
) -> Result<LightBlock, Error> {
use std::convert::TryFrom;

let root = state
.light_store
.highest_trusted_or_verified_before(target_height)
Expand Down
5 changes: 1 addition & 4 deletions light-client/src/peer_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,7 @@ mod tests {
let new_primary = peer_list.replace_faulty_primary(None);
match new_primary {
Err(Error(ErrorDetail::NoWitnessesLeft(_), _)) => {},
_ => panic!(
"expected NoWitnessesLeft error, instead got {:?}",
new_primary
),
_ => panic!("expected NoWitnessesLeft error, instead got {new_primary:?}"),
}
}

Expand Down
8 changes: 4 additions & 4 deletions light-client/src/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ mod tests {

match result {
Err(Error(ErrorDetail::NoWitnesses(_), _)) => {},
_ => panic!("expected NoWitnesses error, instead got {:?}", result),
_ => panic!("expected NoWitnesses error, instead got {result:?}"),
}
}

Expand Down Expand Up @@ -724,14 +724,14 @@ mod tests {
assert_eq!(e.source.code(), rpc::Code::InvalidRequest)
},
_ => {
panic!("expected Response error, instead got {:?}", e)
panic!("expected Response error, instead got {e:?}")
},
},
_ => {
panic!("expected Rpc error, instead got {:?}", e)
panic!("expected Rpc error, instead got {e:?}")
},
},
_ => panic!("expected Io error, instead got {:?}", result),
_ => panic!("expected Io error, instead got {result:?}"),
}
}

Expand Down
8 changes: 4 additions & 4 deletions light-client/tests/model_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ mod mbt {
}
input.block.signed_header.commit.round = (round as u16).into();
(
format!("commit round from {} into {}", r, round),
format!("commit round from {r} into {round}"),
LiteVerdict::Invalid,
)
}
Expand Down Expand Up @@ -586,7 +586,7 @@ mod mbt {
);
},
Err(e) => {
output_env.logln(&format!(" > lite: {:?}", e));
output_env.logln(&format!(" > lite: {e:?}"));
match e {
Verdict::Invalid(_) => assert_eq!(input.verdict, LiteVerdict::Invalid),
Verdict::NotEnoughTrust(_) => {
Expand Down Expand Up @@ -668,7 +668,7 @@ mod mbt {
// Check for the necessary programs
let check_program = |program| {
if !Command::exists_program(program) {
output_env.logln(&format!(" > {} not found", program));
output_env.logln(&format!(" > {program} not found"));
return false;
}
true
Expand All @@ -692,7 +692,7 @@ mod mbt {
ApalacheRun::Counterexample(_) => (),
run => panic!("{}", run.message()),
},
Err(e) => panic!("failed to run Apalache; reason: {}", e),
Err(e) => panic!("failed to run Apalache; reason: {e}"),
}
output_env.copy_file_from_env_as(env, "counterexample.tla", &tla_test);

Expand Down
2 changes: 1 addition & 1 deletion light-client/tests/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn run_multipeer_test(tc: LightClientTest<LightBlock>) {

for provider in tc.witnesses.into_iter() {
let peer_id = provider.value.lite_blocks[0].provider;
println!("Witness: {}", peer_id);
println!("Witness: {peer_id}");
let io = MockIo::new(provider.value.lite_blocks);
let instance = make_instance(peer_id, tc.trust_options.clone(), io.clone(), tc.now);
peer_list.witness(peer_id, instance);
Expand Down
5 changes: 1 addition & 4 deletions p2p/src/secret_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ impl Handshake<AwaitingEphKey> {
&mut self,
remote_eph_pubkey: EphemeralPublic,
) -> Result<Handshake<AwaitingAuthSig>, Error> {
let local_eph_privkey = match self.state.local_eph_privkey.take() {
Some(key) => key,
None => return Err(Error::missing_secret()),
};
let Some(local_eph_privkey) = self.state.local_eph_privkey.take() else { return Err(Error::missing_secret()) };
let local_eph_pubkey = EphemeralPublic::from(&local_eph_privkey);

// Compute common shared secret.
Expand Down
8 changes: 4 additions & 4 deletions pbt-gen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "tendermint-pbt-gen"
version = "0.28.0"
authors = ["Informal Systems <hello@informal.systems>"]
edition = "2018"
name = "tendermint-pbt-gen"
version = "0.28.0"
authors = ["Informal Systems <hello@informal.systems>"]
edition = "2021"
license = "Apache-2.0"
readme = "README.md"
categories = ["development-tools"]
Expand Down
Loading

0 comments on commit 3c79d14

Please sign in to comment.