Skip to content

Commit 5256761

Browse files
authored
Rollup merge of rust-lang#89944 - mbartlett21:patch-2, r=Mark-Simulacrum
Change `Duration::[try_]from_secs_{f32, f64}` underflow error The error message now says that it was a negative value. Fixes rust-lang#89913.
2 parents 8c210e0 + fe060bf commit 5256761

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

Diff for: library/core/src/time.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ impl Duration {
756756
} else if nanos >= MAX_NANOS_F64 {
757757
Err(FromSecsError { kind: FromSecsErrorKind::Overflow })
758758
} else if nanos < 0.0 {
759-
Err(FromSecsError { kind: FromSecsErrorKind::Underflow })
759+
Err(FromSecsError { kind: FromSecsErrorKind::Negative })
760760
} else {
761761
let nanos = nanos as u128;
762762
Ok(Duration {
@@ -818,7 +818,7 @@ impl Duration {
818818
} else if nanos >= MAX_NANOS_F32 {
819819
Err(FromSecsError { kind: FromSecsErrorKind::Overflow })
820820
} else if nanos < 0.0 {
821-
Err(FromSecsError { kind: FromSecsErrorKind::Underflow })
821+
Err(FromSecsError { kind: FromSecsErrorKind::Negative })
822822
} else {
823823
let nanos = nanos as u128;
824824
Ok(Duration {
@@ -1274,11 +1274,9 @@ pub struct FromSecsError {
12741274
impl FromSecsError {
12751275
const fn description(&self) -> &'static str {
12761276
match self.kind {
1277-
FromSecsErrorKind::NonFinite => {
1278-
"got non-finite value when converting float to duration"
1279-
}
1277+
FromSecsErrorKind::NonFinite => "non-finite value when converting float to duration",
12801278
FromSecsErrorKind::Overflow => "overflow when converting float to duration",
1281-
FromSecsErrorKind::Underflow => "underflow when converting float to duration",
1279+
FromSecsErrorKind::Negative => "negative value when converting float to duration",
12821280
}
12831281
}
12841282
}
@@ -1292,10 +1290,10 @@ impl fmt::Display for FromSecsError {
12921290

12931291
#[derive(Debug, Clone, PartialEq, Eq)]
12941292
enum FromSecsErrorKind {
1295-
// Value is not a finite value (either infinity or NaN).
1293+
// Value is not a finite value (either + or - infinity or NaN).
12961294
NonFinite,
12971295
// Value is too large to store in a `Duration`.
12981296
Overflow,
1299-
// Value is less than `0.0`.
1300-
Underflow,
1297+
// Value is negative.
1298+
Negative,
13011299
}

0 commit comments

Comments
 (0)