diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2021-10-22 19:42:47 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-22 19:42:47 +0900 |
| commit | 8b7adf63e17ea2391b40668501cedb8099e3f8ca (patch) | |
| tree | b270f698d2de3ebecbd86cd587d9b8fe9f9aa870 | |
| parent | 327d8073e2a7939e12676940fc4847ca78be3f84 (diff) | |
| parent | fe060bf2477313c6621368097e1d41cade8ca163 (diff) | |
| download | rust-8b7adf63e17ea2391b40668501cedb8099e3f8ca.tar.gz rust-8b7adf63e17ea2391b40668501cedb8099e3f8ca.zip | |
Rollup merge of #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 #89913.
| -rw-r--r-- | library/core/src/time.rs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/library/core/src/time.rs b/library/core/src/time.rs index 5a74f39e8bc..7114f2d652e 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -756,7 +756,7 @@ impl Duration { } else if nanos >= MAX_NANOS_F64 { Err(FromSecsError { kind: FromSecsErrorKind::Overflow }) } else if nanos < 0.0 { - Err(FromSecsError { kind: FromSecsErrorKind::Underflow }) + Err(FromSecsError { kind: FromSecsErrorKind::Negative }) } else { let nanos = nanos as u128; Ok(Duration { @@ -818,7 +818,7 @@ impl Duration { } else if nanos >= MAX_NANOS_F32 { Err(FromSecsError { kind: FromSecsErrorKind::Overflow }) } else if nanos < 0.0 { - Err(FromSecsError { kind: FromSecsErrorKind::Underflow }) + Err(FromSecsError { kind: FromSecsErrorKind::Negative }) } else { let nanos = nanos as u128; Ok(Duration { @@ -1274,11 +1274,9 @@ pub struct FromSecsError { impl FromSecsError { const fn description(&self) -> &'static str { match self.kind { - FromSecsErrorKind::NonFinite => { - "got non-finite value when converting float to duration" - } + FromSecsErrorKind::NonFinite => "non-finite value when converting float to duration", FromSecsErrorKind::Overflow => "overflow when converting float to duration", - FromSecsErrorKind::Underflow => "underflow when converting float to duration", + FromSecsErrorKind::Negative => "negative value when converting float to duration", } } } @@ -1292,10 +1290,10 @@ impl fmt::Display for FromSecsError { #[derive(Debug, Clone, PartialEq, Eq)] enum FromSecsErrorKind { - // Value is not a finite value (either infinity or NaN). + // Value is not a finite value (either + or - infinity or NaN). NonFinite, // Value is too large to store in a `Duration`. Overflow, - // Value is less than `0.0`. - Underflow, + // Value is negative. + Negative, } |
