From bb167d4a9a51435a4435bdd10a19a28d5de3a261 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Sun, 13 Oct 2019 15:21:56 +0200 Subject: [PATCH] refactor: fix compiler warnings --- benchmark_crate/benches/shootout-pidigits.rs | 8 +++---- src/bigint.rs | 4 ++-- src/biguint.rs | 22 ++++++++++---------- tests/bigint.rs | 11 +++++----- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/benchmark_crate/benches/shootout-pidigits.rs b/benchmark_crate/benches/shootout-pidigits.rs index 0005d61..9884ff8 100644 --- a/benchmark_crate/benches/shootout-pidigits.rs +++ b/benchmark_crate/benches/shootout-pidigits.rs @@ -109,9 +109,9 @@ fn pidigits(n: isize, out: &mut io::Write) -> io::Result<()> { } } - try!(write!(out, "{}", d)); + write!(out, "{}", d)?; if i % 10 == 0 { - try!(write!(out, "\t:{}\n", i)); + write!(out, "\t:{}\n", i)?; } context.eliminate_digit(d); @@ -120,9 +120,9 @@ fn pidigits(n: isize, out: &mut io::Write) -> io::Result<()> { let m = n % 10; if m != 0 { for _ in m..10 { - try!(write!(out, " ")); + write!(out, " ")?; } - try!(write!(out, "\t:{}\n", n)); + write!(out, "\t:{}\n", n)?; } Ok(()) } diff --git a/src/bigint.rs b/src/bigint.rs index 6db713b..9252464 100644 --- a/src/bigint.rs +++ b/src/bigint.rs @@ -1,8 +1,8 @@ #![allow(clippy::suspicious_arithmetic_impl)] #[allow(deprecated, unused_imports)] use alloc::borrow::Cow; -use alloc::vec::Vec; use alloc::string::String; +use alloc::vec::Vec; use core::cmp::Ordering::{self, Equal, Greater, Less}; use core::default::Default; use core::hash::{Hash, Hasher}; @@ -703,7 +703,7 @@ impl Num for BigInt { } else { Plus }; - let bu = try!(BigUint::from_str_radix(s, radix)); + let bu = BigUint::from_str_radix(s, radix)?; Ok(BigInt::from_biguint(sign, bu)) } } diff --git a/src/biguint.rs b/src/biguint.rs index 9bff151..b644a4b 100644 --- a/src/biguint.rs +++ b/src/biguint.rs @@ -1,7 +1,7 @@ #[allow(deprecated, unused_imports)] use alloc::borrow::Cow; -use alloc::vec::Vec; use alloc::string::String; +use alloc::vec::Vec; use core::cmp::Ordering::{self, Equal, Greater, Less}; use core::default::Default; use core::hash::{Hash, Hasher}; @@ -13,7 +13,7 @@ use core::ops::{ use core::str::{self, FromStr}; use core::{cmp, fmt, mem}; use core::{f32, f64}; -use core::{u64, u32, u8}; +use core::{u32, u64, u8}; #[cfg(not(feature = "std"))] use libm::F64Ext; @@ -25,11 +25,11 @@ use serde; use zeroize::Zeroize; use integer::{Integer, Roots}; -use num_traits::{ - CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, FromPrimitive, Num, One, Pow, - ToPrimitive, Unsigned, Zero, -}; use num_traits::float::FloatCore; +use num_traits::{ + CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, FromPrimitive, Num, One, Pow, ToPrimitive, + Unsigned, Zero, +}; use BigInt; @@ -44,7 +44,7 @@ use self::monty::monty_modpow; use super::VEC_SIZE; use crate::algorithms::{__add2, __sub2rev, add2, sub2, sub2rev}; use crate::algorithms::{biguint_shl, biguint_shr}; -use crate::algorithms::{cmp_slice, fls, ilog2, idiv_ceil}; +use crate::algorithms::{cmp_slice, fls, idiv_ceil, ilog2}; use crate::algorithms::{div_rem, div_rem_digit, mac_with_carry, mul3, scalar_mul}; use crate::algorithms::{extended_gcd, mod_inverse}; use crate::traits::{ExtendedGcd, ModInverse}; @@ -260,9 +260,9 @@ impl Num for BigUint { let mut v = Vec::with_capacity(s.len()); for b in s.bytes() { let d = match b { - b'0'...b'9' => b - b'0', - b'a'...b'z' => b - b'a' + 10, - b'A'...b'Z' => b - b'A' + 10, + b'0'..=b'9' => b - b'0', + b'a'..=b'z' => b - b'a' + 10, + b'A'..=b'Z' => b - b'A' + 10, b'_' => continue, _ => u8::MAX, }; @@ -2542,7 +2542,7 @@ impl<'de> serde::Deserialize<'de> for BigUint { where D: serde::Deserializer<'de>, { - let data: Vec = try!(Vec::deserialize(deserializer)); + let data: Vec = Vec::deserialize(deserializer)?; Ok(BigUint::new(data)) } } diff --git a/tests/bigint.rs b/tests/bigint.rs index ec1739e..74de1da 100644 --- a/tests/bigint.rs +++ b/tests/bigint.rs @@ -20,8 +20,8 @@ use std::{i16, i32, i64, i8, isize}; use std::{u16, u32, u64, u8, usize}; use num_integer::Integer; -use num_traits::{FromPrimitive, Num, One, Pow, Signed, ToPrimitive, Zero}; use num_traits::float::FloatCore; +use num_traits::{FromPrimitive, Num, One, Pow, Signed, ToPrimitive, Zero}; mod consts; use consts::*; @@ -677,9 +677,9 @@ fn test_add() { fn test_add_mut() { for elm in SUM_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; - let mut a = BigInt::from_slice(Plus, a_vec); - let mut b = BigInt::from_slice(Plus, b_vec); - let mut c = BigInt::from_slice(Plus, c_vec); + let a = BigInt::from_slice(Plus, a_vec); + let b = BigInt::from_slice(Plus, b_vec); + let c = BigInt::from_slice(Plus, c_vec); let (na, nb, nc) = (-&a, -&b, -&c); assert_op!(a + b == c); @@ -1120,7 +1120,6 @@ fn test_negative_shr() { #[test] #[cfg(feature = "rand")] fn test_random_shr() { - #[cfg(feature = "std")] fn thread_rng() -> impl rand::Rng { rand::thread_rng() @@ -1132,8 +1131,8 @@ fn test_random_shr() { rand::rngs::StdRng::seed_from_u64(4) } - use rand::Rng; use rand::distributions::Standard; + use rand::Rng; let mut rng = thread_rng();