浏览代码

Upgrade to 2018 edition

Josh Stone 3 年之前
父节点
当前提交
da2bd55647
共有 11 个文件被更改,包括 47 次插入53 次删除
  1. 1 0
      Cargo.toml
  2. 0 2
      build.rs
  3. 8 11
      src/float.rs
  4. 5 5
      src/int.rs
  5. 15 15
      src/lib.rs
  6. 8 8
      src/ops/euclid.rs
  7. 4 4
      src/ops/mul_add.rs
  8. 2 2
      src/pow.rs
  9. 1 1
      src/real.rs
  10. 2 2
      src/sign.rs
  11. 1 3
      tests/cast.rs

+ 1 - 0
Cargo.toml

@@ -12,6 +12,7 @@ version = "0.2.15"
 readme = "README.md"
 build = "build.rs"
 exclude = ["/bors.toml", "/ci/*", "/.github/*"]
+edition = "2018"
 
 [package.metadata.docs.rs]
 features = ["std"]

+ 0 - 2
build.rs

@@ -1,5 +1,3 @@
-extern crate autocfg;
-
 use std::env;
 
 fn main() {

+ 8 - 11
src/float.rs

@@ -5,10 +5,7 @@ use core::ops::{Add, Div, Neg};
 use core::f32;
 use core::f64;
 
-use {Num, NumCast, ToPrimitive};
-
-#[cfg(all(not(feature = "std"), feature = "libm"))]
-use libm;
+use crate::{Num, NumCast, ToPrimitive};
 
 /// Generic trait for floating point numbers that works with `no_std`.
 ///
@@ -2244,7 +2241,7 @@ mod tests {
 
     #[test]
     fn convert_deg_rad() {
-        use float::FloatCore;
+        use crate::float::FloatCore;
 
         for &(deg, rad) in &DEG_RAD_PAIRS {
             assert!((FloatCore::to_degrees(rad) - deg).abs() < 1e-6);
@@ -2260,7 +2257,7 @@ mod tests {
     #[test]
     fn convert_deg_rad_std() {
         for &(deg, rad) in &DEG_RAD_PAIRS {
-            use Float;
+            use crate::Float;
 
             assert!((Float::to_degrees(rad) - deg).abs() < 1e-6);
             assert!((Float::to_radians(deg) - rad).abs() < 1e-6);
@@ -2276,7 +2273,7 @@ mod tests {
     // To avoid the failure, the test is limited to `no_std` builds.
     #[cfg(not(feature = "std"))]
     fn to_degrees_rounding() {
-        use float::FloatCore;
+        use crate::float::FloatCore;
 
         assert_eq!(
             FloatCore::to_degrees(1_f32),
@@ -2287,7 +2284,7 @@ mod tests {
     #[test]
     #[cfg(any(feature = "std", feature = "libm"))]
     fn extra_logs() {
-        use float::{Float, FloatConst};
+        use crate::float::{Float, FloatConst};
 
         fn check<F: Float + FloatConst>(diff: F) {
             let _2 = F::from(2.0).unwrap();
@@ -2306,7 +2303,7 @@ mod tests {
     #[test]
     #[cfg(any(feature = "std", feature = "libm"))]
     fn copysign() {
-        use float::Float;
+        use crate::float::Float;
         test_copysign_generic(2.0_f32, -2.0_f32, f32::nan());
         test_copysign_generic(2.0_f64, -2.0_f64, f64::nan());
         test_copysignf(2.0_f32, -2.0_f32, f32::nan());
@@ -2314,8 +2311,8 @@ mod tests {
 
     #[cfg(any(feature = "std", feature = "libm"))]
     fn test_copysignf(p: f32, n: f32, nan: f32) {
+        use crate::float::Float;
         use core::ops::Neg;
-        use float::Float;
 
         assert!(p.is_sign_positive());
         assert!(n.is_sign_negative());
@@ -2333,7 +2330,7 @@ mod tests {
     }
 
     #[cfg(any(feature = "std", feature = "libm"))]
-    fn test_copysign_generic<F: ::float::Float + ::core::fmt::Debug>(p: F, n: F, nan: F) {
+    fn test_copysign_generic<F: crate::float::Float + ::core::fmt::Debug>(p: F, n: F, nan: F) {
         assert!(p.is_sign_positive());
         assert!(n.is_sign_negative());
         assert!(nan.is_nan());

+ 5 - 5
src/int.rs

@@ -1,9 +1,9 @@
 use core::ops::{BitAnd, BitOr, BitXor, Not, Shl, Shr};
 
-use bounds::Bounded;
-use ops::checked::*;
-use ops::saturating::Saturating;
-use {Num, NumCast};
+use crate::bounds::Bounded;
+use crate::ops::checked::*;
+use crate::ops::saturating::Saturating;
+use crate::{Num, NumCast};
 
 /// Generic trait for primitive integers.
 ///
@@ -513,7 +513,7 @@ prim_int_impl!(isize, isize, usize);
 
 #[cfg(test)]
 mod tests {
-    use int::PrimInt;
+    use crate::int::PrimInt;
 
     #[test]
     pub fn reverse_bits() {

+ 15 - 15
src/lib.rs

@@ -29,26 +29,26 @@ use core::num::Wrapping;
 use core::ops::{Add, Div, Mul, Rem, Sub};
 use core::ops::{AddAssign, DivAssign, MulAssign, RemAssign, SubAssign};
 
-pub use bounds::Bounded;
+pub use crate::bounds::Bounded;
 #[cfg(any(feature = "std", feature = "libm"))]
-pub use float::Float;
-pub use float::FloatConst;
+pub use crate::float::Float;
+pub use crate::float::FloatConst;
 // pub use real::{FloatCore, Real}; // NOTE: Don't do this, it breaks `use num_traits::*;`.
-pub use cast::{cast, AsPrimitive, FromPrimitive, NumCast, ToPrimitive};
-pub use identities::{one, zero, One, Zero};
-pub use int::PrimInt;
-pub use ops::checked::{
+pub use crate::cast::{cast, AsPrimitive, FromPrimitive, NumCast, ToPrimitive};
+pub use crate::identities::{one, zero, One, Zero};
+pub use crate::int::PrimInt;
+pub use crate::ops::checked::{
     CheckedAdd, CheckedDiv, CheckedMul, CheckedNeg, CheckedRem, CheckedShl, CheckedShr, CheckedSub,
 };
-pub use ops::euclid::{CheckedEuclid, Euclid};
-pub use ops::inv::Inv;
-pub use ops::mul_add::{MulAdd, MulAddAssign};
-pub use ops::saturating::{Saturating, SaturatingAdd, SaturatingMul, SaturatingSub};
-pub use ops::wrapping::{
+pub use crate::ops::euclid::{CheckedEuclid, Euclid};
+pub use crate::ops::inv::Inv;
+pub use crate::ops::mul_add::{MulAdd, MulAddAssign};
+pub use crate::ops::saturating::{Saturating, SaturatingAdd, SaturatingMul, SaturatingSub};
+pub use crate::ops::wrapping::{
     WrappingAdd, WrappingMul, WrappingNeg, WrappingShl, WrappingShr, WrappingSub,
 };
-pub use pow::{checked_pow, pow, Pow};
-pub use sign::{abs, abs_sub, signum, Signed, Unsigned};
+pub use crate::pow::{checked_pow, pow, Pow};
+pub use crate::sign::{abs, abs_sub, signum, Signed, Unsigned};
 
 #[macro_use]
 mod macros;
@@ -199,7 +199,7 @@ pub struct ParseFloatError {
 }
 
 impl fmt::Display for ParseFloatError {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         let description = match self.kind {
             FloatErrorKind::Empty => "cannot parse float from empty string",
             FloatErrorKind::Invalid => "invalid float literal",

+ 8 - 8
src/ops/euclid.rs

@@ -130,7 +130,7 @@ euclid_forward_impl!(f32 f64);
 impl Euclid for f32 {
     #[inline]
     fn div_euclid(&self, v: &f32) -> f32 {
-        let q = <f32 as ::float::FloatCore>::trunc(self / v);
+        let q = <f32 as crate::float::FloatCore>::trunc(self / v);
         if self % v < 0.0 {
             return if *v > 0.0 { q - 1.0 } else { q + 1.0 };
         }
@@ -141,7 +141,7 @@ impl Euclid for f32 {
     fn rem_euclid(&self, v: &f32) -> f32 {
         let r = self % v;
         if r < 0.0 {
-            r + <f32 as ::float::FloatCore>::abs(*v)
+            r + <f32 as crate::float::FloatCore>::abs(*v)
         } else {
             r
         }
@@ -152,7 +152,7 @@ impl Euclid for f32 {
 impl Euclid for f64 {
     #[inline]
     fn div_euclid(&self, v: &f64) -> f64 {
-        let q = <f64 as ::float::FloatCore>::trunc(self / v);
+        let q = <f64 as crate::float::FloatCore>::trunc(self / v);
         if self % v < 0.0 {
             return if *v > 0.0 { q - 1.0 } else { q + 1.0 };
         }
@@ -163,7 +163,7 @@ impl Euclid for f64 {
     fn rem_euclid(&self, v: &f64) -> f64 {
         let r = self % v;
         if r < 0.0 {
-            r + <f64 as ::float::FloatCore>::abs(*v)
+            r + <f64 as crate::float::FloatCore>::abs(*v)
         } else {
             r
         }
@@ -312,13 +312,13 @@ mod tests {
                         let x: $t = 12.1;
                         let y: $t = 3.2;
                         assert!(Euclid::div_euclid(&x, &y) * y + Euclid::rem_euclid(&x, &y) - x
-                        <= 46.4 * <$t as ::float::FloatCore>::epsilon());
+                        <= 46.4 * <$t as crate::float::FloatCore>::epsilon());
                         assert!(Euclid::div_euclid(&x, &-y) * -y + Euclid::rem_euclid(&x, &-y) - x
-                        <= 46.4 * <$t as ::float::FloatCore>::epsilon());
+                        <= 46.4 * <$t as crate::float::FloatCore>::epsilon());
                         assert!(Euclid::div_euclid(&-x, &y) * y + Euclid::rem_euclid(&-x, &y) + x
-                        <= 46.4 * <$t as ::float::FloatCore>::epsilon());
+                        <= 46.4 * <$t as crate::float::FloatCore>::epsilon());
                         assert!(Euclid::div_euclid(&-x, &-y) * -y + Euclid::rem_euclid(&-x, &-y) + x
-                        <= 46.4 * <$t as ::float::FloatCore>::epsilon());
+                        <= 46.4 * <$t as crate::float::FloatCore>::epsilon());
                     }
                 )+
             };

+ 4 - 4
src/ops/mul_add.rs

@@ -40,7 +40,7 @@ impl MulAdd<f32, f32> for f32 {
 
     #[inline]
     fn mul_add(self, a: Self, b: Self) -> Self::Output {
-        <Self as ::Float>::mul_add(self, a, b)
+        <Self as crate::Float>::mul_add(self, a, b)
     }
 }
 
@@ -50,7 +50,7 @@ impl MulAdd<f64, f64> for f64 {
 
     #[inline]
     fn mul_add(self, a: Self, b: Self) -> Self::Output {
-        <Self as ::Float>::mul_add(self, a, b)
+        <Self as crate::Float>::mul_add(self, a, b)
     }
 }
 
@@ -75,7 +75,7 @@ mul_add_impl!(MulAdd for i128 u128);
 impl MulAddAssign<f32, f32> for f32 {
     #[inline]
     fn mul_add_assign(&mut self, a: Self, b: Self) {
-        *self = <Self as ::Float>::mul_add(*self, a, b)
+        *self = <Self as crate::Float>::mul_add(*self, a, b)
     }
 }
 
@@ -83,7 +83,7 @@ impl MulAddAssign<f32, f32> for f32 {
 impl MulAddAssign<f64, f64> for f64 {
     #[inline]
     fn mul_add_assign(&mut self, a: Self, b: Self) {
-        *self = <Self as ::Float>::mul_add(*self, a, b)
+        *self = <Self as crate::Float>::mul_add(*self, a, b)
     }
 }
 

+ 2 - 2
src/pow.rs

@@ -1,6 +1,6 @@
+use crate::{CheckedMul, One};
 use core::num::Wrapping;
 use core::ops::Mul;
-use {CheckedMul, One};
 
 /// Binary operator for raising a value to a power.
 pub trait Pow<RHS> {
@@ -155,7 +155,7 @@ pow_impl!(Wrapping<isize>);
 #[cfg(any(feature = "std", feature = "libm"))]
 mod float_impls {
     use super::Pow;
-    use Float;
+    use crate::Float;
 
     pow_impl!(f32, i8, i32, <f32 as Float>::powi);
     pow_impl!(f32, u8, i32, <f32 as Float>::powi);

+ 1 - 1
src/real.rs

@@ -2,7 +2,7 @@
 
 use core::ops::Neg;
 
-use {Float, Num, NumCast};
+use crate::{Float, Num, NumCast};
 
 // NOTE: These doctests have the same issue as those in src/float.rs.
 // They're testing the inherent methods directly, and not those of `Real`.

+ 2 - 2
src/sign.rs

@@ -1,8 +1,8 @@
 use core::num::Wrapping;
 use core::ops::Neg;
 
-use float::FloatCore;
-use Num;
+use crate::float::FloatCore;
+use crate::Num;
 
 /// Useful functions for signed numbers (i.e. numbers that can be negative).
 pub trait Signed: Sized + Num + Neg<Output = Self> {

+ 1 - 3
tests/cast.rs

@@ -6,8 +6,6 @@
 #[macro_use]
 extern crate std;
 
-extern crate num_traits;
-
 use num_traits::cast::*;
 use num_traits::Bounded;
 
@@ -163,7 +161,7 @@ fn cast_to_i128_checks_overflow() {
 }
 
 #[cfg(feature = "std")]
-fn dbg(args: ::core::fmt::Arguments) {
+fn dbg(args: ::core::fmt::Arguments<'_>) {
     println!("{}", args);
 }