1
+ #![ allow( clippy:: unimplemented) ]
2
+
1
3
use difftest:: config:: OutputType ;
2
4
use std:: marker:: PhantomData ;
3
5
@@ -67,16 +69,16 @@ impl OutputDiffer for RawDiffer {
67
69
( Some ( & b1) , Some ( & b2) ) if b1 != b2 => {
68
70
differences. push ( Difference {
69
71
index : i,
70
- value1 : format ! ( "{}" , b1 ) ,
71
- value2 : format ! ( "{}" , b2 ) ,
72
+ value1 : format ! ( "{b1}" ) ,
73
+ value2 : format ! ( "{b2}" ) ,
72
74
absolute_diff : DiffMagnitude :: Incomparable ,
73
75
relative_diff : DiffMagnitude :: Incomparable ,
74
76
} ) ;
75
77
}
76
78
( Some ( & b1) , None ) => {
77
79
differences. push ( Difference {
78
80
index : i,
79
- value1 : format ! ( "{}" , b1 ) ,
81
+ value1 : format ! ( "{b1}" ) ,
80
82
value2 : "" . to_string ( ) ,
81
83
absolute_diff : DiffMagnitude :: Incomparable ,
82
84
relative_diff : DiffMagnitude :: Incomparable ,
@@ -86,7 +88,7 @@ impl OutputDiffer for RawDiffer {
86
88
differences. push ( Difference {
87
89
index : i,
88
90
value1 : "" . to_string ( ) ,
89
- value2 : format ! ( "{}" , b2 ) ,
91
+ value2 : format ! ( "{b2}" ) ,
90
92
absolute_diff : DiffMagnitude :: Incomparable ,
91
93
relative_diff : DiffMagnitude :: Incomparable ,
92
94
} ) ;
@@ -129,8 +131,8 @@ impl DifferenceDisplay for RawDiffer {
129
131
} ;
130
132
(
131
133
format ! ( "{:>3}" , format!( "{:02x}" , byte) ) ,
132
- format ! ( "{:3}" , byte ) ,
133
- format ! ( "{:^5}" , ascii ) ,
134
+ format ! ( "{byte :3}" ) ,
135
+ format ! ( "{ascii :^5}" ) ,
134
136
)
135
137
} ;
136
138
@@ -151,8 +153,8 @@ impl DifferenceDisplay for RawDiffer {
151
153
} ;
152
154
(
153
155
format ! ( "{:>3}" , format!( "{:02x}" , byte) ) ,
154
- format ! ( "{:3}" , byte ) ,
155
- format ! ( "{:^5}" , ascii ) ,
156
+ format ! ( "{byte :3}" ) ,
157
+ format ! ( "{ascii :^5}" ) ,
156
158
)
157
159
} ;
158
160
@@ -191,11 +193,7 @@ impl DifferenceDisplay for RawDiffer {
191
193
let mut result = table. to_string ( ) ;
192
194
193
195
if diffs. len ( ) > 10 {
194
- let last_line_width = result
195
- . lines ( )
196
- . last ( )
197
- . map ( |l| l. chars ( ) . count ( ) )
198
- . unwrap_or ( 0 ) ;
196
+ let last_line_width = result. lines ( ) . last ( ) . map_or ( 0 , |l| l. chars ( ) . count ( ) ) ;
199
197
result. push_str ( & format ! (
200
198
"\n {:>width$}" ,
201
199
format!( "... {} more differences" , diffs. len( ) - 10 ) ,
@@ -226,7 +224,7 @@ impl DifferenceDisplay for RawDiffer {
226
224
for ( i, chunk) in output. chunks ( 16 ) . enumerate ( ) {
227
225
write ! ( file, "{:08x}: " , i * 16 ) ?;
228
226
for byte in chunk {
229
- write ! ( file, "{:02x} " , byte ) ?;
227
+ write ! ( file, "{byte :02x} " ) ?;
230
228
}
231
229
writeln ! ( file) ?;
232
230
}
@@ -255,7 +253,7 @@ impl NumericType for f32 {
255
253
"F32"
256
254
}
257
255
fn format_value ( value : Self ) -> String {
258
- format ! ( "{:.9}" , value )
256
+ format ! ( "{value :.9}" )
259
257
}
260
258
fn can_have_relative_diff ( ) -> bool {
261
259
true
@@ -280,7 +278,7 @@ impl NumericType for u32 {
280
278
"U32"
281
279
}
282
280
fn format_value ( value : Self ) -> String {
283
- format ! ( "{}" , value )
281
+ format ! ( "{value}" )
284
282
}
285
283
fn can_have_relative_diff ( ) -> bool {
286
284
true
@@ -379,7 +377,7 @@ impl<T: NumericType> DifferenceDisplay for NumericDiffer<T> {
379
377
let abs_str = match & d. absolute_diff {
380
378
DiffMagnitude :: Numeric ( val) => {
381
379
if T :: can_have_relative_diff ( ) {
382
- format ! ( "{:.3e}" , val )
380
+ format ! ( "{val :.3e}" )
383
381
} else {
384
382
format ! ( "{}" , * val as u64 )
385
383
}
@@ -431,11 +429,7 @@ impl<T: NumericType> DifferenceDisplay for NumericDiffer<T> {
431
429
let mut result = table. to_string ( ) ;
432
430
433
431
if diffs. len ( ) > 10 {
434
- let last_line_width = result
435
- . lines ( )
436
- . last ( )
437
- . map ( |l| l. chars ( ) . count ( ) )
438
- . unwrap_or ( 0 ) ;
432
+ let last_line_width = result. lines ( ) . last ( ) . map_or ( 0 , |l| l. chars ( ) . count ( ) ) ;
439
433
result. push_str ( & format ! (
440
434
"\n {:>width$}" ,
441
435
format!( "... {} more differences" , diffs. len( ) - 10 ) ,
@@ -482,9 +476,9 @@ impl From<OutputType> for Box<dyn OutputDiffer + Send + Sync> {
482
476
match output_type {
483
477
OutputType :: Raw => Box :: new ( RawDiffer ) ,
484
478
OutputType :: F32 => Box :: new ( F32Differ :: default ( ) ) ,
485
- OutputType :: F64 => todo ! ( "F64Differ not implemented yet" ) ,
479
+ OutputType :: F64 => unimplemented ! ( "F64Differ not implemented yet" ) ,
486
480
OutputType :: U32 => Box :: new ( U32Differ :: default ( ) ) ,
487
- OutputType :: I32 => todo ! ( "I32Differ not implemented yet" ) ,
481
+ OutputType :: I32 => unimplemented ! ( "I32Differ not implemented yet" ) ,
488
482
}
489
483
}
490
484
}
@@ -494,9 +488,9 @@ impl From<OutputType> for Box<dyn DifferenceDisplay + Send + Sync> {
494
488
match output_type {
495
489
OutputType :: Raw => Box :: new ( RawDiffer ) ,
496
490
OutputType :: F32 => Box :: new ( F32Differ :: default ( ) ) ,
497
- OutputType :: F64 => todo ! ( "F64Display not implemented yet" ) ,
491
+ OutputType :: F64 => unimplemented ! ( "F64Differ not implemented yet" ) ,
498
492
OutputType :: U32 => Box :: new ( U32Differ :: default ( ) ) ,
499
- OutputType :: I32 => todo ! ( "I32Display not implemented yet" ) ,
493
+ OutputType :: I32 => unimplemented ! ( "I32Differ not implemented yet" ) ,
500
494
}
501
495
}
502
496
}
@@ -533,11 +527,11 @@ mod tests {
533
527
assert_eq ! ( diffs[ 0 ] . value2, "5" ) ;
534
528
match & diffs[ 0 ] . absolute_diff {
535
529
DiffMagnitude :: Numeric ( val) => assert_eq ! ( * val, 3.0 ) ,
536
- _ => panic ! ( "Expected numeric difference" ) ,
530
+ DiffMagnitude :: Incomparable => panic ! ( "Expected numeric difference" ) ,
537
531
}
538
532
match & diffs[ 0 ] . relative_diff {
539
533
DiffMagnitude :: Numeric ( val) => assert_eq ! ( * val, 3.0 / 5.0 ) , // 3/5 = 0.6
540
- _ => panic ! ( "Expected numeric relative diff for U32" ) ,
534
+ DiffMagnitude :: Incomparable => panic ! ( "Expected numeric relative diff for U32" ) ,
541
535
}
542
536
543
537
// Check second difference (index 3: 4 vs 7)
@@ -546,7 +540,7 @@ mod tests {
546
540
assert_eq ! ( diffs[ 1 ] . value2, "7" ) ;
547
541
match & diffs[ 1 ] . absolute_diff {
548
542
DiffMagnitude :: Numeric ( val) => assert_eq ! ( * val, 3.0 ) ,
549
- _ => panic ! ( "Expected numeric difference" ) ,
543
+ DiffMagnitude :: Incomparable => panic ! ( "Expected numeric difference" ) ,
550
544
}
551
545
}
552
546
@@ -665,12 +659,12 @@ mod tests {
665
659
666
660
match numeric {
667
661
DiffMagnitude :: Numeric ( val) => assert_eq ! ( val, 42.0 ) ,
668
- _ => panic ! ( "Expected numeric" ) ,
662
+ DiffMagnitude :: Incomparable => panic ! ( "Expected numeric" ) ,
669
663
}
670
664
671
665
match incomparable {
672
666
DiffMagnitude :: Incomparable => { }
673
- _ => panic ! ( "Expected incomparable" ) ,
667
+ DiffMagnitude :: Numeric ( _ ) => panic ! ( "Expected incomparable" ) ,
674
668
}
675
669
}
676
670
}
0 commit comments