Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Duration::[try_]from_secs_{f32, f64} underflow error #89944

Merged
merged 1 commit into from
Oct 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions library/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
}
}
}
Expand All @@ -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,
}