Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup(clippy): Remove unnecessary try_into() with cargo clippy --fix #7940

Merged
merged 6 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions zebra-chain/src/orchard/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,12 @@ impl PartialEq<[u8; 11]> for Diversifier {
}
}

impl TryFrom<Diversifier> for pallas::Affine {
type Error = &'static str;

impl From<Diversifier> for pallas::Affine {
/// Get a diversified base point from a diversifier value in affine
/// representation.
fn try_from(d: Diversifier) -> Result<Self, Self::Error> {
if let Ok(projective_point) = pallas::Point::try_from(d) {
Ok(projective_point.into())
} else {
Err("Invalid Diversifier -> pallas::Affine")
}
fn from(d: Diversifier) -> Self {
let projective_point = pallas::Point::from(d);
projective_point.into()
}
}

Expand Down
4 changes: 1 addition & 3 deletions zebra-chain/src/sapling/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ impl Arbitrary for Output {
.prop_map(|(enc_ciphertext, out_ciphertext, zkproof)| Self {
cv: ExtendedPoint::generator().try_into().unwrap(),
cm_u: NoteCommitment(AffinePoint::identity()).extract_u(),
ephemeral_key: keys::EphemeralPublicKey(
ExtendedPoint::generator().try_into().unwrap(),
),
ephemeral_key: keys::EphemeralPublicKey(ExtendedPoint::generator().into()),
enc_ciphertext,
out_ciphertext,
zkproof,
Expand Down
4 changes: 2 additions & 2 deletions zebra-consensus/src/block/subsidy/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ pub fn halving_divisor(height: Height, network: Network) -> Option<u64> {
Some(halving_div)
} else {
let pre_blossom_height = blossom_height - SLOW_START_SHIFT;
let scaled_pre_blossom_height = pre_blossom_height
* HeightDiff::try_from(BLOSSOM_POW_TARGET_SPACING_RATIO).expect("constant is positive");
let scaled_pre_blossom_height =
pre_blossom_height * HeightDiff::from(BLOSSOM_POW_TARGET_SPACING_RATIO);

let post_blossom_height = height - blossom_height;

Expand Down
6 changes: 2 additions & 4 deletions zebra-consensus/src/primitives/halo2/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn generate_test_vectors() {
let action = zebra_chain::orchard::Action {
cv: a.cv_net().to_bytes().try_into().unwrap(),
nullifier: a.nullifier().to_bytes().try_into().unwrap(),
rk: <[u8; 32]>::from(a.rk()).try_into().unwrap(),
rk: <[u8; 32]>::from(a.rk()).into(),
cm_x: pallas::Base::from_repr(a.cmx().into()).unwrap(),
ephemeral_key: a.encrypted_note().epk_bytes.try_into().unwrap(),
enc_ciphertext: a.encrypted_note().enc_ciphertext.into(),
Expand All @@ -89,9 +89,7 @@ fn generate_test_vectors() {
.collect::<Vec<_>>()
.try_into()
.unwrap(),
binding_sig: <[u8; 64]>::from(bundle.authorization().binding_signature())
.try_into()
.unwrap(),
binding_sig: <[u8; 64]>::from(bundle.authorization().binding_signature()).into(),
}
})
.collect();
Expand Down
6 changes: 1 addition & 5 deletions zebra-network/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,11 +523,7 @@ mod tests {

assert!(
INVENTORY_ROTATION_INTERVAL
< Duration::from_secs(
POST_BLOSSOM_POW_TARGET_SPACING
.try_into()
.expect("non-negative"),
),
< Duration::from_secs(POST_BLOSSOM_POW_TARGET_SPACING.into()),
"we should expire inventory every time 1-2 new blocks get generated"
);
}
Expand Down
2 changes: 1 addition & 1 deletion zebra-script/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl CachedFfiTransaction {
};

if err == zcash_script_error_t_zcash_script_ERR_OK {
let ret = ret.try_into().expect("c_uint fits in a u64");
let ret = ret.into();
Ok(ret)
} else {
Err(Error::from(err))
Expand Down
3 changes: 1 addition & 2 deletions zebra-state/src/service/check/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ pub fn transparent_coinbase_spend(

match spend_restriction {
OnlyShieldedOutputs { spend_height } => {
let min_spend_height =
utxo.height + MIN_TRANSPARENT_COINBASE_MATURITY.try_into().unwrap();
let min_spend_height = utxo.height + MIN_TRANSPARENT_COINBASE_MATURITY.into();
let min_spend_height =
min_spend_height.expect("valid UTXOs have coinbase heights far below Height::MAX");
if spend_height >= min_spend_height {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ impl TransactionIndex {

/// Returns this index as a `usize`
pub fn as_usize(&self) -> usize {
self.0
.try_into()
.expect("the maximum valid index fits in usize")
self.0.into()
}

/// Creates a transaction index from a `u64`.
teor2345 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -108,9 +106,7 @@ impl TransactionIndex {
/// Returns this index as a `u64`
#[allow(dead_code)]
pub fn as_u64(&self) -> u64 {
self.0
.try_into()
.expect("the maximum valid index fits in u64")
self.0.into()
}
}

Expand Down
3 changes: 1 addition & 2 deletions zebra-utils/src/bin/zebra-checkpoints/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ async fn main() -> Result<()> {

// Checkpoints must be on the main chain, so we skip blocks that are within the
// Zcash reorg limit.
let height_limit = height_limit
- HeightDiff::try_from(MIN_TRANSPARENT_COINBASE_MATURITY).expect("constant fits in i32");
let height_limit = height_limit - HeightDiff::from(MIN_TRANSPARENT_COINBASE_MATURITY);
let height_limit = height_limit
.ok_or_else(|| {
eyre!(
Expand Down
7 changes: 1 addition & 6 deletions zebrad/src/components/mempool/crawler/tests/timing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Timing tests for the mempool crawler.

use std::convert::TryInto;

use zebra_chain::parameters::POST_BLOSSOM_POW_TARGET_SPACING;
use zebra_network::constants::{DEFAULT_CRAWL_NEW_PEER_INTERVAL, HANDSHAKE_TIMEOUT};

Expand All @@ -10,10 +8,7 @@ use crate::components::mempool::crawler::RATE_LIMIT_DELAY;
#[test]
fn ensure_timing_consistent() {
assert!(
RATE_LIMIT_DELAY.as_secs()
< POST_BLOSSOM_POW_TARGET_SPACING
.try_into()
.expect("not negative"),
RATE_LIMIT_DELAY.as_secs() < POST_BLOSSOM_POW_TARGET_SPACING.into(),
"a mempool crawl should complete before most new blocks"
);

Expand Down
14 changes: 4 additions & 10 deletions zebrad/src/components/sync/tests/timing.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
//! Check the relationship between various sync timeouts and delays.

use std::{
convert::TryInto,
sync::{
atomic::{AtomicU8, Ordering},
Arc,
},
use std::sync::{
atomic::{AtomicU8, Ordering},
Arc,
};

use futures::future;
Expand Down Expand Up @@ -79,10 +76,7 @@ fn ensure_timeouts_consistent() {
);

assert!(
SYNC_RESTART_DELAY.as_secs()
< POST_BLOSSOM_POW_TARGET_SPACING
.try_into()
.expect("not negative"),
SYNC_RESTART_DELAY.as_secs() < POST_BLOSSOM_POW_TARGET_SPACING.into(),
"a syncer tip crawl should complete before most new blocks"
);

Expand Down
3 changes: 1 addition & 2 deletions zebrad/tests/common/checkpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,7 @@ pub fn wait_for_zebra_checkpoints_generation<
test_type: TestType,
show_zebrad_logs: bool,
) -> Result<(TestChild<TempDir>, TestChild<P>)> {
let last_checkpoint_gap = HeightDiff::try_from(MIN_TRANSPARENT_COINBASE_MATURITY)
.expect("constant fits in HeightDiff")
let last_checkpoint_gap = HeightDiff::from(MIN_TRANSPARENT_COINBASE_MATURITY)
+ HeightDiff::try_from(MAX_CHECKPOINT_HEIGHT_GAP).expect("constant fits in HeightDiff");
let expected_final_checkpoint_height =
(zebra_tip_height - last_checkpoint_gap).expect("network tip is high enough");
Expand Down
Loading