Resolve clippy lints in lexical

This commit is contained in:
David Tolnay 2020-06-05 21:15:05 -07:00
parent 0e37ea0af9
commit 286e047aac
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
11 changed files with 46 additions and 35 deletions

View File

@ -179,9 +179,9 @@ where
let b = fp.into_downward_float::<F>();
if b.is_special() {
// We have a non-finite number, we get to leave early.
return b;
b
} else {
return bhcomp(b, integer, fraction, exponent);
bhcomp(b, integer, fraction, exponent)
}
}
@ -197,7 +197,7 @@ mod tests {
// valid
let mantissa = (1 << f32::MANTISSA_SIZE) - 1;
let (min_exp, max_exp) = f32::exponent_limit();
for exp in min_exp..max_exp + 1 {
for exp in min_exp..=max_exp {
let f = fast_path::<f32>(mantissa, exp);
assert!(f.is_some(), "should be valid {:?}.", (mantissa, exp));
}
@ -236,7 +236,7 @@ mod tests {
// valid
let mantissa = (1 << f64::MANTISSA_SIZE) - 1;
let (min_exp, max_exp) = f64::exponent_limit();
for exp in min_exp..max_exp + 1 {
for exp in min_exp..=max_exp {
let f = fast_path::<f64>(mantissa, exp);
assert!(f.is_some(), "should be valid {:?}.", (mantissa, exp));
}

View File

@ -23,12 +23,12 @@ impl Default for Bigint {
impl Math for Bigint {
#[inline]
fn data<'a>(&'a self) -> &'a Vec<Limb> {
fn data(&self) -> &Vec<Limb> {
&self.data
}
#[inline]
fn data_mut<'a>(&'a mut self) -> &'a mut Vec<Limb> {
fn data_mut(&mut self) -> &mut Vec<Limb> {
&mut self.data
}
}

View File

@ -9,5 +9,5 @@ pub(crate) fn to_digit(c: u8) -> Option<u32> {
// Add digit to mantissa.
#[inline]
pub(crate) fn add_digit(value: u64, digit: u32) -> Option<u64> {
return value.checked_mul(10)?.checked_add(digit as u64);
value.checked_mul(10)?.checked_add(digit as u64)
}

View File

@ -68,9 +68,10 @@ impl FloatErrors for u64 {
let denormal_exp = bias - 63;
// This is always a valid u32, since (denormal_exp - fp.exp)
// will always be positive and the significand size is {23, 52}.
let extrabits = match fp.exp <= denormal_exp {
true => 64 - F::MANTISSA_SIZE + denormal_exp - fp.exp,
false => 63 - F::MANTISSA_SIZE,
let extrabits = if fp.exp <= denormal_exp {
64 - F::MANTISSA_SIZE + denormal_exp - fp.exp
} else {
63 - F::MANTISSA_SIZE
};
// Our logic is as follows: we want to determine if the actual

View File

@ -389,7 +389,7 @@ mod tests {
1e-40, 2e-40, 1e-35, 2e-35, 1e-30, 2e-30, 1e-25, 2e-25, 1e-20, 2e-20, 1e-15, 2e-15,
1e-10, 2e-10, 1e-5, 2e-5, 1.0, 2.0, 1e5, 2e5, 1e10, 2e10, 1e15, 2e15, 1e20, 2e20,
];
for value in values.iter() {
for value in &values {
assert_normalized_eq(
ExtendedFloat::from_float(*value),
ExtendedFloat::from_float(*value as f64),
@ -515,7 +515,7 @@ mod tests {
assert_eq!(x.into_float::<f32>(), f32::INFINITY);
// Integers.
for int in INTEGERS.iter() {
for int in &INTEGERS {
let fp = ExtendedFloat { mant: *int, exp: 0 };
assert_eq!(fp.into_float::<f32>(), *int as f32, "{:?} as f32", *int);
}
@ -656,7 +656,7 @@ mod tests {
assert_eq!(x.into_float::<f64>(), 5e-324);
// Integers.
for int in INTEGERS.iter() {
for int in &INTEGERS {
let fp = ExtendedFloat { mant: *int, exp: 0 };
assert_eq!(fp.into_float::<f64>(), *int as f64, "{:?} as f64", *int);
}

View File

@ -617,7 +617,7 @@ const POW5_14: [u64; 298] = [
9640,
];
pub(crate) const POW5: [&'static [u64]; 14] = [
pub(crate) const POW5: [&[u64]; 14] = [
&POW5_1, &POW5_2, &POW5_3, &POW5_4, &POW5_5, &POW5_6, &POW5_7, &POW5_8, &POW5_9, &POW5_10,
&POW5_11, &POW5_12, &POW5_13, &POW5_14,
];

View File

@ -576,8 +576,7 @@ mod small {
// minus leading zero bits.
let nlz = leading_zeros(x);
bits.checked_mul(x.len())
.map(|v| v - nlz)
.unwrap_or(usize::max_value())
.map_or_else(usize::max_value, |v| v - nlz)
}
// SHL
@ -668,9 +667,9 @@ mod large {
#[inline]
pub fn compare(x: &[Limb], y: &[Limb]) -> cmp::Ordering {
if x.len() > y.len() {
return cmp::Ordering::Greater;
cmp::Ordering::Greater
} else if x.len() < y.len() {
return cmp::Ordering::Less;
cmp::Ordering::Less
} else {
let iter = x.iter().rev().zip(y.iter().rev());
for (&xi, &yi) in iter {
@ -681,7 +680,7 @@ mod large {
}
}
// Equal case.
return cmp::Ordering::Equal;
cmp::Ordering::Equal
}
}
@ -809,7 +808,7 @@ mod large {
/// Split two buffers into halfway, into (lo, hi).
#[inline]
pub fn karatsuba_split<'a>(z: &'a [Limb], m: usize) -> (&'a [Limb], &'a [Limb]) {
pub fn karatsuba_split(z: &[Limb], m: usize) -> (&[Limb], &[Limb]) {
(&z[..m], &z[m..])
}
@ -862,7 +861,7 @@ mod large {
// two numbers, except we're using splits on `y`, and the intermediate
// step is a Karatsuba multiplication.
let mut start = 0;
while y.len() != 0 {
while !y.is_empty() {
let m = x.len().min(y.len());
let (yl, yh) = karatsuba_split(y, m);
let prod = karatsuba_mul(x, yl);
@ -912,10 +911,10 @@ pub(crate) trait Math: Clone + Sized + Default {
// DATA
/// Get access to the underlying data
fn data<'a>(&'a self) -> &'a Vec<Limb>;
fn data(&self) -> &Vec<Limb>;
/// Get access to the underlying data
fn data_mut<'a>(&'a mut self) -> &'a mut Vec<Limb>;
fn data_mut(&mut self) -> &mut Vec<Limb>;
// RELATIVE OPERATIONS
@ -1019,12 +1018,12 @@ mod tests {
impl Math for Bigint {
#[inline]
fn data<'a>(&'a self) -> &'a Vec<Limb> {
fn data(&self) -> &Vec<Limb> {
&self.data
}
#[inline]
fn data_mut<'a>(&'a mut self) -> &'a mut Vec<Limb> {
fn data_mut(&mut self) -> &mut Vec<Limb> {
&mut self.data
}
}

View File

@ -22,9 +22,10 @@ pub(crate) fn lower_n_mask(n: u64) -> u64 {
let bits: u64 = mem::size_of::<u64>() as u64 * 8;
debug_assert!(n <= bits, "lower_n_mask() overflow in shl.");
match n == bits {
true => u64::max_value(),
false => (1 << n) - 1,
if n == bits {
u64::max_value()
} else {
(1 << n) - 1
}
}
@ -34,9 +35,10 @@ pub(crate) fn lower_n_halfway(n: u64) -> u64 {
let bits: u64 = mem::size_of::<u64>() as u64 * 8;
debug_assert!(n <= bits, "lower_n_halfway() overflow in shl.");
match n == 0 {
true => 0,
false => nth_bit(n - 1),
if n == 0 {
0
} else {
nth_bit(n - 1)
}
}

View File

@ -25,9 +25,10 @@ pub(crate) fn overflowing_shr(fp: &mut ExtendedFloat, shift: i32) {
"overflowing_shr() overflow in shift right."
);
fp.mant = match shift as u64 == bits {
true => 0,
false => fp.mant >> shift,
fp.mant = if shift as u64 == bits {
0
} else {
fp.mant >> shift
};
fp.exp += shift;
}

View File

@ -108,7 +108,7 @@ pub trait Slice<T> {
/// Create a reverse view of the vector for indexing.
#[inline]
fn rview<'a>(&'a self) -> ReverseView<'a, T> {
fn rview(&self) -> ReverseView<T> {
ReverseView {
inner: self.as_slice(),
}

View File

@ -304,8 +304,11 @@
#![deny(clippy::all, clippy::pedantic)]
// Ignored clippy lints
#![allow(
clippy::comparison_chain,
clippy::deprecated_cfg_attr,
clippy::doc_markdown,
clippy::excessive_precision,
clippy::float_cmp,
clippy::match_single_binding,
clippy::needless_doctest_main,
clippy::transmute_ptr_to_ptr
@ -315,12 +318,15 @@
// Deserializer::from_str, into_iter
clippy::should_implement_trait,
// integer and float ser/de requires these sorts of casts
clippy::cast_possible_truncation,
clippy::cast_possible_wrap,
clippy::cast_precision_loss,
clippy::cast_sign_loss,
// correctly used
clippy::enum_glob_use,
clippy::if_not_else,
clippy::integer_division,
clippy::similar_names,
clippy::wildcard_imports,
// things are often more readable this way
clippy::cast_lossless,
@ -328,6 +334,8 @@
clippy::shadow_unrelated,
clippy::single_match_else,
clippy::too_many_lines,
clippy::unreadable_literal,
clippy::unseparated_literal_suffix,
clippy::use_self,
clippy::zero_prefixed_literal,
// we support older compilers