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
@@ -194,8 +196,7 @@ impl DifferenceDisplay for RawDiffer {
194
196
let last_line_width = result
195
197
. lines ( )
196
198
. last ( )
197
- . map ( |l| l. chars ( ) . count ( ) )
198
- . unwrap_or ( 0 ) ;
199
+ . map_or ( 0 , |l| l. chars ( ) . count ( ) ) ;
199
200
result. push_str ( & format ! (
200
201
"\n {:>width$}" ,
201
202
format!( "... {} more differences" , diffs. len( ) - 10 ) ,
@@ -226,7 +227,7 @@ impl DifferenceDisplay for RawDiffer {
226
227
for ( i, chunk) in output. chunks ( 16 ) . enumerate ( ) {
227
228
write ! ( file, "{:08x}: " , i * 16 ) ?;
228
229
for byte in chunk {
229
- write ! ( file, "{:02x} " , byte ) ?;
230
+ write ! ( file, "{byte :02x} " ) ?;
230
231
}
231
232
writeln ! ( file) ?;
232
233
}
@@ -255,7 +256,7 @@ impl NumericType for f32 {
255
256
"F32"
256
257
}
257
258
fn format_value ( value : Self ) -> String {
258
- format ! ( "{:.9}" , value )
259
+ format ! ( "{value :.9}" )
259
260
}
260
261
fn can_have_relative_diff ( ) -> bool {
261
262
true
@@ -280,7 +281,7 @@ impl NumericType for u32 {
280
281
"U32"
281
282
}
282
283
fn format_value ( value : Self ) -> String {
283
- format ! ( "{}" , value )
284
+ format ! ( "{value}" )
284
285
}
285
286
fn can_have_relative_diff ( ) -> bool {
286
287
true
@@ -379,7 +380,7 @@ impl<T: NumericType> DifferenceDisplay for NumericDiffer<T> {
379
380
let abs_str = match & d. absolute_diff {
380
381
DiffMagnitude :: Numeric ( val) => {
381
382
if T :: can_have_relative_diff ( ) {
382
- format ! ( "{:.3e}" , val )
383
+ format ! ( "{val :.3e}" )
383
384
} else {
384
385
format ! ( "{}" , * val as u64 )
385
386
}
@@ -434,8 +435,7 @@ impl<T: NumericType> DifferenceDisplay for NumericDiffer<T> {
434
435
let last_line_width = result
435
436
. lines ( )
436
437
. last ( )
437
- . map ( |l| l. chars ( ) . count ( ) )
438
- . unwrap_or ( 0 ) ;
438
+ . map_or ( 0 , |l| l. chars ( ) . count ( ) ) ;
439
439
result. push_str ( & format ! (
440
440
"\n {:>width$}" ,
441
441
format!( "... {} more differences" , diffs. len( ) - 10 ) ,
@@ -482,9 +482,9 @@ impl From<OutputType> for Box<dyn OutputDiffer + Send + Sync> {
482
482
match output_type {
483
483
OutputType :: Raw => Box :: new ( RawDiffer ) ,
484
484
OutputType :: F32 => Box :: new ( F32Differ :: default ( ) ) ,
485
- OutputType :: F64 => todo ! ( "F64Differ not implemented yet" ) ,
485
+ OutputType :: F64 => unimplemented ! ( "F64Differ not implemented yet" ) ,
486
486
OutputType :: U32 => Box :: new ( U32Differ :: default ( ) ) ,
487
- OutputType :: I32 => todo ! ( "I32Differ not implemented yet" ) ,
487
+ OutputType :: I32 => unimplemented ! ( "I32Differ not implemented yet" ) ,
488
488
}
489
489
}
490
490
}
@@ -494,9 +494,9 @@ impl From<OutputType> for Box<dyn DifferenceDisplay + Send + Sync> {
494
494
match output_type {
495
495
OutputType :: Raw => Box :: new ( RawDiffer ) ,
496
496
OutputType :: F32 => Box :: new ( F32Differ :: default ( ) ) ,
497
- OutputType :: F64 => todo ! ( "F64Display not implemented yet" ) ,
497
+ OutputType :: F64 => unimplemented ! ( "F64Differ not implemented yet" ) ,
498
498
OutputType :: U32 => Box :: new ( U32Differ :: default ( ) ) ,
499
- OutputType :: I32 => todo ! ( "I32Display not implemented yet" ) ,
499
+ OutputType :: I32 => unimplemented ! ( "I32Differ not implemented yet" ) ,
500
500
}
501
501
}
502
502
}
@@ -533,11 +533,11 @@ mod tests {
533
533
assert_eq ! ( diffs[ 0 ] . value2, "5" ) ;
534
534
match & diffs[ 0 ] . absolute_diff {
535
535
DiffMagnitude :: Numeric ( val) => assert_eq ! ( * val, 3.0 ) ,
536
- _ => panic ! ( "Expected numeric difference" ) ,
536
+ DiffMagnitude :: Incomparable => panic ! ( "Expected numeric difference" ) ,
537
537
}
538
538
match & diffs[ 0 ] . relative_diff {
539
539
DiffMagnitude :: Numeric ( val) => assert_eq ! ( * val, 3.0 / 5.0 ) , // 3/5 = 0.6
540
- _ => panic ! ( "Expected numeric relative diff for U32" ) ,
540
+ DiffMagnitude :: Incomparable => panic ! ( "Expected numeric relative diff for U32" ) ,
541
541
}
542
542
543
543
// Check second difference (index 3: 4 vs 7)
@@ -546,7 +546,7 @@ mod tests {
546
546
assert_eq ! ( diffs[ 1 ] . value2, "7" ) ;
547
547
match & diffs[ 1 ] . absolute_diff {
548
548
DiffMagnitude :: Numeric ( val) => assert_eq ! ( * val, 3.0 ) ,
549
- _ => panic ! ( "Expected numeric difference" ) ,
549
+ DiffMagnitude :: Incomparable => panic ! ( "Expected numeric difference" ) ,
550
550
}
551
551
}
552
552
@@ -665,12 +665,12 @@ mod tests {
665
665
666
666
match numeric {
667
667
DiffMagnitude :: Numeric ( val) => assert_eq ! ( val, 42.0 ) ,
668
- _ => panic ! ( "Expected numeric" ) ,
668
+ DiffMagnitude :: Incomparable => panic ! ( "Expected numeric" ) ,
669
669
}
670
670
671
671
match incomparable {
672
672
DiffMagnitude :: Incomparable => { }
673
- _ => panic ! ( "Expected incomparable" ) ,
673
+ DiffMagnitude :: Numeric ( _ ) => panic ! ( "Expected incomparable" ) ,
674
674
}
675
675
}
676
676
}
0 commit comments