2121#[ cfg_attr( test, macro_use) ]
2222extern crate std;
2323
24- extern crate num_traits as traits;
25-
26- #[ cfg( feature = "serde" ) ]
27- extern crate serde;
28-
29- #[ cfg( feature = "rand" ) ]
30- extern crate rand;
31-
3224use core:: fmt;
3325#[ cfg( test) ]
3426use core:: hash;
@@ -38,19 +30,19 @@ use core::str::FromStr;
3830#[ cfg( feature = "std" ) ]
3931use std:: error:: Error ;
4032
41- use traits :: { Inv , MulAdd , Num , One , Pow , Signed , Zero } ;
33+ use num_traits :: { Inv , MulAdd , Num , One , Pow , Signed , Zero } ;
4234
4335#[ cfg( feature = "std" ) ]
44- use traits :: float:: Float ;
45- use traits :: float:: FloatCore ;
36+ use num_traits :: float:: Float ;
37+ use num_traits :: float:: FloatCore ;
4638
4739mod cast;
4840mod pow;
4941
5042#[ cfg( feature = "rand" ) ]
5143mod crand;
5244#[ cfg( feature = "rand" ) ]
53- pub use crand:: ComplexDistribution ;
45+ pub use crate :: crand:: ComplexDistribution ;
5446
5547// FIXME #1284: handle complex NaN & infinity etc. This
5648// probably doesn't map to C's _Complex correctly.
@@ -96,7 +88,7 @@ impl<T> Complex<T> {
9688 /// Create a new Complex
9789 #[ inline]
9890 pub const fn new ( re : T , im : T ) -> Self {
99- Complex { re : re , im : im }
91+ Complex { re, im }
10092 }
10193}
10294
@@ -759,9 +751,9 @@ impl<T: Clone + Num> Rem<Complex<T>> for Complex<T> {
759751mod opassign {
760752 use core:: ops:: { AddAssign , DivAssign , MulAssign , RemAssign , SubAssign } ;
761753
762- use traits :: { MulAddAssign , NumAssign } ;
754+ use num_traits :: { MulAddAssign , NumAssign } ;
763755
764- use Complex ;
756+ use crate :: Complex ;
765757
766758 impl < T : Clone + NumAssign > AddAssign for Complex < T > {
767759 fn add_assign ( & mut self , other : Self ) {
@@ -1149,11 +1141,11 @@ macro_rules! write_complex {
11491141 } ;
11501142
11511143 fn fmt_re_im(
1152- f: & mut fmt:: Formatter ,
1144+ f: & mut fmt:: Formatter < ' _> ,
11531145 re_neg: bool ,
11541146 im_neg: bool ,
1155- real: fmt:: Arguments ,
1156- imag: fmt:: Arguments ,
1147+ real: fmt:: Arguments < ' _> ,
1148+ imag: fmt:: Arguments < ' _> ,
11571149 ) -> fmt:: Result {
11581150 let prefix = if f. alternate( ) { $prefix } else { "" } ;
11591151 let sign = if re_neg {
@@ -1191,7 +1183,7 @@ macro_rules! write_complex {
11911183
11921184 #[ cfg( feature = "std" ) ]
11931185 // Currently, we can only apply width using an intermediate `String` (and thus `std`)
1194- fn fmt_complex( f: & mut fmt:: Formatter , complex: fmt:: Arguments ) -> fmt:: Result {
1186+ fn fmt_complex( f: & mut fmt:: Formatter < ' _> , complex: fmt:: Arguments < ' _> ) -> fmt:: Result {
11951187 use std:: string:: ToString ;
11961188 if let Some ( width) = f. width( ) {
11971189 write!( f, "{0: >1$}" , complex. to_string( ) , width)
@@ -1201,7 +1193,7 @@ macro_rules! write_complex {
12011193 }
12021194
12031195 #[ cfg( not( feature = "std" ) ) ]
1204- fn fmt_complex( f: & mut fmt:: Formatter , complex: fmt:: Arguments ) -> fmt:: Result {
1196+ fn fmt_complex( f: & mut fmt:: Formatter < ' _> , complex: fmt:: Arguments < ' _> ) -> fmt:: Result {
12051197 write!( f, "{}" , complex)
12061198 }
12071199 } } ;
@@ -1212,7 +1204,7 @@ impl<T> fmt::Display for Complex<T>
12121204where
12131205 T : fmt:: Display + Num + PartialOrd + Clone ,
12141206{
1215- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1207+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
12161208 write_complex ! ( f, "" , "" , self . re, self . im, T )
12171209 }
12181210}
@@ -1221,7 +1213,7 @@ impl<T> fmt::LowerExp for Complex<T>
12211213where
12221214 T : fmt:: LowerExp + Num + PartialOrd + Clone ,
12231215{
1224- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1216+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
12251217 write_complex ! ( f, "e" , "" , self . re, self . im, T )
12261218 }
12271219}
@@ -1230,7 +1222,7 @@ impl<T> fmt::UpperExp for Complex<T>
12301222where
12311223 T : fmt:: UpperExp + Num + PartialOrd + Clone ,
12321224{
1233- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1225+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
12341226 write_complex ! ( f, "E" , "" , self . re, self . im, T )
12351227 }
12361228}
@@ -1239,7 +1231,7 @@ impl<T> fmt::LowerHex for Complex<T>
12391231where
12401232 T : fmt:: LowerHex + Num + PartialOrd + Clone ,
12411233{
1242- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1234+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
12431235 write_complex ! ( f, "x" , "0x" , self . re, self . im, T )
12441236 }
12451237}
@@ -1248,7 +1240,7 @@ impl<T> fmt::UpperHex for Complex<T>
12481240where
12491241 T : fmt:: UpperHex + Num + PartialOrd + Clone ,
12501242{
1251- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1243+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
12521244 write_complex ! ( f, "X" , "0x" , self . re, self . im, T )
12531245 }
12541246}
@@ -1257,7 +1249,7 @@ impl<T> fmt::Octal for Complex<T>
12571249where
12581250 T : fmt:: Octal + Num + PartialOrd + Clone ,
12591251{
1260- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1252+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
12611253 write_complex ! ( f, "o" , "0o" , self . re, self . im, T )
12621254 }
12631255}
@@ -1266,7 +1258,7 @@ impl<T> fmt::Binary for Complex<T>
12661258where
12671259 T : fmt:: Binary + Num + PartialOrd + Clone ,
12681260{
1269- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1261+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
12701262 write_complex ! ( f, "b" , "0b" , self . re, self . im, T )
12711263 }
12721264}
@@ -1281,10 +1273,10 @@ where
12811273 #[ inline]
12821274 fn is_whitespace ( c : char ) -> bool {
12831275 match c {
1284- ' ' | '\x09' ... '\x0d' => true ,
1276+ ' ' | '\x09' ..= '\x0d' => true ,
12851277 _ if c > '\x7f' => match c {
12861278 '\u{0085}' | '\u{00a0}' | '\u{1680}' => true ,
1287- '\u{2000}' ... '\u{200a}' => true ,
1279+ '\u{2000}' ..= '\u{200a}' => true ,
12881280 '\u{2028}' | '\u{2029}' | '\u{202f}' | '\u{205f}' => true ,
12891281 '\u{3000}' => true ,
12901282 _ => false ,
@@ -1312,7 +1304,7 @@ where
13121304 // ignore '+'/'-' if part of an exponent
13131305 if ( c == b'+' || c == b'-' ) && !( p == b'e' || p == b'E' ) {
13141306 // trim whitespace around the separator
1315- a = & s[ ..i + 1 ] . trim_right_matches ( is_whitespace) ;
1307+ a = & s[ ..=i ] . trim_right_matches ( is_whitespace) ;
13161308 b = & s[ i + 2 ..] . trim_left_matches ( is_whitespace) ;
13171309 neg_b = c == b'-' ;
13181310
@@ -1326,10 +1318,7 @@ where
13261318 // split off real and imaginary parts
13271319 if b. is_empty ( ) {
13281320 // input was either pure real or pure imaginary
1329- b = match a. ends_with ( imag) {
1330- false => "0i" ,
1331- true => "0" ,
1332- } ;
1321+ b = if a. ends_with ( imag) { "0" } else { "0i" } ;
13331322 }
13341323
13351324 let re;
@@ -1351,7 +1340,7 @@ where
13511340 }
13521341
13531342 // parse re
1354- let re = try! ( from ( re) . map_err ( ParseComplexError :: from_error) ) ;
1343+ let re = from ( re) . map_err ( ParseComplexError :: from_error) ? ;
13551344 let re = if neg_re { T :: zero ( ) - re } else { re } ;
13561345
13571346 // pop imaginary unit off
@@ -1364,7 +1353,7 @@ where
13641353 }
13651354
13661355 // parse im
1367- let im = try! ( from ( im) . map_err ( ParseComplexError :: from_error) ) ;
1356+ let im = from ( im) . map_err ( ParseComplexError :: from_error) ? ;
13681357 let im = if neg_im { T :: zero ( ) - im } else { im } ;
13691358
13701359 Ok ( Complex :: new ( re, im) )
@@ -1451,7 +1440,7 @@ where
14511440 where
14521441 D : serde:: Deserializer < ' de > ,
14531442 {
1454- let ( re, im) = try! ( serde:: Deserialize :: deserialize ( deserializer) ) ;
1443+ let ( re, im) = serde:: Deserialize :: deserialize ( deserializer) ? ;
14551444 Ok ( Self :: new ( re, im) )
14561445 }
14571446}
@@ -1483,6 +1472,7 @@ impl<E> ParseComplexError<E> {
14831472
14841473#[ cfg( feature = "std" ) ]
14851474impl < E : Error > Error for ParseComplexError < E > {
1475+ #[ allow( deprecated) ]
14861476 fn description ( & self ) -> & str {
14871477 match self . kind {
14881478 ComplexErrorKind :: ParseError ( ref e) => e. description ( ) ,
@@ -1492,7 +1482,7 @@ impl<E: Error> Error for ParseComplexError<E> {
14921482}
14931483
14941484impl < E : fmt:: Display > fmt:: Display for ParseComplexError < E > {
1495- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1485+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
14961486 match self . kind {
14971487 ComplexErrorKind :: ParseError ( ref e) => e. fmt ( f) ,
14981488 ComplexErrorKind :: ExprError => "invalid or unsupported complex expression" . fmt ( f) ,
@@ -1519,7 +1509,7 @@ mod test {
15191509
15201510 use std:: string:: { String , ToString } ;
15211511
1522- use traits :: { Num , One , Zero } ;
1512+ use num_traits :: { Num , One , Zero } ;
15231513
15241514 pub const _0_0i: Complex64 = Complex { re : 0.0 , im : 0.0 } ;
15251515 pub const _1_0i: Complex64 = Complex { re : 1.0 , im : 0.0 } ;
@@ -1584,6 +1574,7 @@ mod test {
15841574 }
15851575
15861576 #[ test]
1577+ #[ allow( clippy:: float_cmp) ]
15871578 fn test_l1_norm ( ) {
15881579 assert_eq ! ( _0_0i. l1_norm( ) , 0.0 ) ;
15891580 assert_eq ! ( _1_0i. l1_norm( ) , 1.0 ) ;
@@ -1616,11 +1607,12 @@ mod test {
16161607 #[ cfg( feature = "std" ) ]
16171608 mod float {
16181609 use super :: * ;
1619- use traits :: { Float , Pow } ;
1610+ use num_traits :: { Float , Pow } ;
16201611
16211612 #[ test]
16221613 #[ cfg_attr( target_arch = "x86" , ignore) ]
16231614 // FIXME #7158: (maybe?) currently failing on x86.
1615+ #[ allow( clippy:: float_cmp) ]
16241616 fn test_norm ( ) {
16251617 fn test ( c : Complex64 , ns : f64 ) {
16261618 assert_eq ! ( c. norm_sqr( ) , ns) ;
@@ -1811,7 +1803,7 @@ mod test {
18111803 ) ) ;
18121804 assert ! ( close(
18131805 Complex :: new( -1.0 , -0.0 ) . cbrt( ) ,
1814- Complex :: new( 0.5 , -0.75 . sqrt( ) )
1806+ Complex :: new( 0.5 , -( 0.75 . sqrt( ) ) )
18151807 ) ) ;
18161808 assert ! ( close( _0_1i. cbrt( ) , Complex :: new( 0.75 . sqrt( ) , 0.5 ) ) ) ;
18171809 assert ! ( close( _0_1i. conj( ) . cbrt( ) , Complex :: new( 0.75 . sqrt( ) , -0.5 ) ) ) ;
@@ -2231,7 +2223,7 @@ mod test {
22312223
22322224 mod complex_arithmetic {
22332225 use super :: { _05_05i, _0_0i, _0_1i, _1_0i, _1_1i, _4_2i, _neg1_1i, all_consts} ;
2234- use traits :: { MulAdd , MulAddAssign , Zero } ;
2226+ use num_traits :: { MulAdd , MulAddAssign , Zero } ;
22352227
22362228 #[ test]
22372229 fn test_add ( ) {
@@ -2450,9 +2442,9 @@ mod test {
24502442 let a = Complex :: new ( 0i32 , 0i32 ) ;
24512443 let b = Complex :: new ( 1i32 , 0i32 ) ;
24522444 let c = Complex :: new ( 0i32 , 1i32 ) ;
2453- assert ! ( :: hash( & a) != :: hash( & b) ) ;
2454- assert ! ( :: hash( & b) != :: hash( & c) ) ;
2455- assert ! ( :: hash( & c) != :: hash( & a) ) ;
2445+ assert ! ( crate :: hash( & a) != crate :: hash( & b) ) ;
2446+ assert ! ( crate :: hash( & b) != crate :: hash( & c) ) ;
2447+ assert ! ( crate :: hash( & c) != crate :: hash( & a) ) ;
24562448 }
24572449
24582450 #[ test]
@@ -2620,7 +2612,7 @@ mod test {
26202612
26212613 let mut c = Complex :: new ( 1.23 , 4.56 ) ;
26222614 assert ! ( !c. is_zero( ) ) ;
2623- assert_eq ! ( & c + & zero, c) ;
2615+ assert_eq ! ( c + zero, c) ;
26242616
26252617 c. set_zero ( ) ;
26262618 assert ! ( c. is_zero( ) ) ;
@@ -2633,13 +2625,14 @@ mod test {
26332625
26342626 let mut c = Complex :: new ( 1.23 , 4.56 ) ;
26352627 assert ! ( !c. is_one( ) ) ;
2636- assert_eq ! ( & c * & one, c) ;
2628+ assert_eq ! ( c * one, c) ;
26372629
26382630 c. set_one ( ) ;
26392631 assert ! ( c. is_one( ) ) ;
26402632 }
26412633
26422634 #[ test]
2635+ #[ allow( clippy:: float_cmp) ]
26432636 fn test_const ( ) {
26442637 const R : f64 = 12.3 ;
26452638 const I : f64 = -4.5 ;
0 commit comments