File tree Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -323,6 +323,9 @@ impl Duration {
323
323
if seconds > i64:: MAX as f64 || seconds < i64:: MIN as f64 {
324
324
crate :: expect_failed ( "overflow constructing `time::Duration`" ) ;
325
325
}
326
+ if seconds. is_nan ( ) {
327
+ crate :: expect_failed ( "passed NaN to `time::Duration::seconds_f64`" ) ;
328
+ }
326
329
Self :: new_unchecked ( seconds as _ , ( ( seconds % 1. ) * 1_000_000_000. ) as _ )
327
330
}
328
331
@@ -337,6 +340,9 @@ impl Duration {
337
340
if seconds > i64:: MAX as f32 || seconds < i64:: MIN as f32 {
338
341
crate :: expect_failed ( "overflow constructing `time::Duration`" ) ;
339
342
}
343
+ if seconds. is_nan ( ) {
344
+ crate :: expect_failed ( "passed NaN to `time::Duration::seconds_f32`" ) ;
345
+ }
340
346
Self :: new_unchecked ( seconds as _ , ( ( seconds % 1. ) * 1_000_000_000. ) as _ )
341
347
}
342
348
Original file line number Diff line number Diff line change @@ -186,6 +186,7 @@ fn seconds_f64() {
186
186
187
187
assert_panic ! ( Duration :: seconds_f64( f64 :: MAX ) ) ;
188
188
assert_panic ! ( Duration :: seconds_f64( f64 :: MIN ) ) ;
189
+ assert_panic ! ( Duration :: seconds_f64( f64 :: NAN ) ) ;
189
190
}
190
191
191
192
#[ test]
@@ -206,6 +207,7 @@ fn seconds_f32() {
206
207
207
208
assert_panic ! ( Duration :: seconds_f32( f32 :: MAX ) ) ;
208
209
assert_panic ! ( Duration :: seconds_f32( f32 :: MIN ) ) ;
210
+ assert_panic ! ( Duration :: seconds_f32( f32 :: NAN ) ) ;
209
211
}
210
212
211
213
#[ test]
You can’t perform that action at this time.
0 commit comments