From 77509865c4281e0f15c5f9be503d2318a991b271 Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Mon, 20 Jan 2020 09:23:38 +0100 Subject: [PATCH] Address cast possible wrap --- tendermint/src/amino_types/block_id.rs | 8 +++++++- tendermint/src/amino_types/ed25519.rs | 2 +- tendermint/src/amino_types/proposal.rs | 4 ++-- tendermint/src/amino_types/time.rs | 6 +++--- tendermint/src/amino_types/vote.rs | 14 ++++++++------ tendermint/src/block/height.rs | 6 ------ tendermint/src/config/node_key.rs | 1 + tendermint/src/lib.rs | 3 +-- 8 files changed, 23 insertions(+), 21 deletions(-) diff --git a/tendermint/src/amino_types/block_id.rs b/tendermint/src/amino_types/block_id.rs index 673e40c3b..c48967e58 100644 --- a/tendermint/src/amino_types/block_id.rs +++ b/tendermint/src/amino_types/block_id.rs @@ -6,6 +6,7 @@ use crate::{ hash, hash::{Hash, SHA256_HASH_SIZE}, }; +use std::convert::TryFrom; #[derive(Clone, PartialEq, Message)] pub struct BlockId { @@ -93,9 +94,14 @@ impl PartsSetHeader { } } +// TODO(xla): Rework into TryFrom. +#[allow(clippy::fallible_impl_from)] impl From<&parts::Header> for PartsSetHeader { fn from(parts: &parts::Header) -> Self { - Self::new(parts.total as i64, parts.hash.as_bytes().to_vec()) + Self::new( + i64::try_from(parts.total).expect("overflow"), + parts.hash.as_bytes().to_vec(), + ) } } diff --git a/tendermint/src/amino_types/ed25519.rs b/tendermint/src/amino_types/ed25519.rs index 6a4f5e887..26ab1e296 100644 --- a/tendermint/src/amino_types/ed25519.rs +++ b/tendermint/src/amino_types/ed25519.rs @@ -31,7 +31,7 @@ impl From for PublicKey { } // TODO(xla): Either complete implementation or convert to TryFrom. -#[allow(clippy::fallible_impl_from)] +#[allow(clippy::fallible_impl_from, clippy::unimplemented)] impl From for PubKeyResponse { fn from(public_key: PublicKey) -> Self { match public_key { diff --git a/tendermint/src/amino_types/proposal.rs b/tendermint/src/amino_types/proposal.rs index 08e07c4b1..df2f63713 100644 --- a/tendermint/src/amino_types/proposal.rs +++ b/tendermint/src/amino_types/proposal.rs @@ -201,7 +201,7 @@ mod tests { let dt = "2018-02-11T07:09:22.765Z".parse::>().unwrap(); let t = TimeMsg { seconds: dt.timestamp(), - nanos: dt.timestamp_subsec_nanos() as i32, + nanos: i32::try_from(dt.timestamp_subsec_nanos()).expect("overflow"), }; let proposal = Proposal { msg_type: SignedMsgType::Proposal.to_u32(), @@ -260,7 +260,7 @@ mod tests { let dt = "2018-02-11T07:09:22.765Z".parse::>().unwrap(); let t = TimeMsg { seconds: dt.timestamp(), - nanos: dt.timestamp_subsec_nanos() as i32, + nanos: i32::try_from(dt.timestamp_subsec_nanos()).expect("overflow"), }; let proposal = Proposal { msg_type: SignedMsgType::Proposal.to_u32(), diff --git a/tendermint/src/amino_types/time.rs b/tendermint/src/amino_types/time.rs index 54c9abe01..f3a6208d3 100644 --- a/tendermint/src/amino_types/time.rs +++ b/tendermint/src/amino_types/time.rs @@ -5,6 +5,7 @@ use crate::{ time::{ParseTimestamp, Time}, }; use chrono::{TimeZone, Utc}; +use std::convert::TryFrom; use std::time::{Duration, SystemTime, UNIX_EPOCH}; #[derive(Clone, PartialEq, Message)] @@ -28,12 +29,11 @@ impl ParseTimestamp for Msg { #[allow(clippy::fallible_impl_from)] impl From