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.
This commit is contained in:
commit
8b7adf63e1
1 changed files with 7 additions and 9 deletions
|
@ -756,7 +756,7 @@ impl Duration {
|
||||||
} else if nanos >= MAX_NANOS_F64 {
|
} else if nanos >= MAX_NANOS_F64 {
|
||||||
Err(FromSecsError { kind: FromSecsErrorKind::Overflow })
|
Err(FromSecsError { kind: FromSecsErrorKind::Overflow })
|
||||||
} else if nanos < 0.0 {
|
} else if nanos < 0.0 {
|
||||||
Err(FromSecsError { kind: FromSecsErrorKind::Underflow })
|
Err(FromSecsError { kind: FromSecsErrorKind::Negative })
|
||||||
} else {
|
} else {
|
||||||
let nanos = nanos as u128;
|
let nanos = nanos as u128;
|
||||||
Ok(Duration {
|
Ok(Duration {
|
||||||
|
@ -818,7 +818,7 @@ impl Duration {
|
||||||
} else if nanos >= MAX_NANOS_F32 {
|
} else if nanos >= MAX_NANOS_F32 {
|
||||||
Err(FromSecsError { kind: FromSecsErrorKind::Overflow })
|
Err(FromSecsError { kind: FromSecsErrorKind::Overflow })
|
||||||
} else if nanos < 0.0 {
|
} else if nanos < 0.0 {
|
||||||
Err(FromSecsError { kind: FromSecsErrorKind::Underflow })
|
Err(FromSecsError { kind: FromSecsErrorKind::Negative })
|
||||||
} else {
|
} else {
|
||||||
let nanos = nanos as u128;
|
let nanos = nanos as u128;
|
||||||
Ok(Duration {
|
Ok(Duration {
|
||||||
|
@ -1274,11 +1274,9 @@ pub struct FromSecsError {
|
||||||
impl FromSecsError {
|
impl FromSecsError {
|
||||||
const fn description(&self) -> &'static str {
|
const fn description(&self) -> &'static str {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
FromSecsErrorKind::NonFinite => {
|
FromSecsErrorKind::NonFinite => "non-finite value when converting float to duration",
|
||||||
"got non-finite value when converting float to duration"
|
|
||||||
}
|
|
||||||
FromSecsErrorKind::Overflow => "overflow 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)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
enum FromSecsErrorKind {
|
enum FromSecsErrorKind {
|
||||||
// Value is not a finite value (either infinity or NaN).
|
// Value is not a finite value (either + or - infinity or NaN).
|
||||||
NonFinite,
|
NonFinite,
|
||||||
// Value is too large to store in a `Duration`.
|
// Value is too large to store in a `Duration`.
|
||||||
Overflow,
|
Overflow,
|
||||||
// Value is less than `0.0`.
|
// Value is negative.
|
||||||
Underflow,
|
Negative,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue