Skip to content

Missing panic condition on API docs #623

Open
@HeeillWang

Description

@HeeillWang

While I executed fuzzing, I faced some panics by expect. Though those are intentional crash, I think it's better to mention on docs as well. Some of APIs are already explicitly mention the panic condition.

I'll just list up the panic-condition-missing APIs, without reproduce condition as it's too obvious.

time/time/src/date.rs

Lines 1304 to 1307 in 6248992

fn add(self, duration: Duration) -> Self::Output {
self.checked_add(duration)
.expect("overflow adding duration to date")
}

time/time/src/duration.rs

Lines 515 to 535 in 6248992

/// Creates a new `Duration` from the specified number of seconds represented as `f32`.
///
/// ```rust
/// # use time::{Duration, ext::NumericalDuration};
/// assert_eq!(Duration::seconds_f32(0.5), 0.5.seconds());
/// assert_eq!(Duration::seconds_f32(-0.5), (-0.5).seconds());
/// ```
pub fn seconds_f32(seconds: f32) -> Self {
try_from_secs!(
secs = seconds,
mantissa_bits = 23,
exponent_bits = 8,
offset = 41,
bits_ty = u32,
bits_ty_signed = i32,
double_ty = u64,
float_ty = f32,
is_nan = crate::expect_failed("passed NaN to `time::Duration::seconds_f32`"),
is_overflow = crate::expect_failed("overflow constructing `time::Duration`"),
)
}

time/time/src/duration.rs

Lines 493 to 513 in 6248992

/// Creates a new `Duration` from the specified number of seconds represented as `f64`.
///
/// ```rust
/// # use time::{Duration, ext::NumericalDuration};
/// assert_eq!(Duration::seconds_f64(0.5), 0.5.seconds());
/// assert_eq!(Duration::seconds_f64(-0.5), -0.5.seconds());
/// ```
pub fn seconds_f64(seconds: f64) -> Self {
try_from_secs!(
secs = seconds,
mantissa_bits = 52,
exponent_bits = 11,
offset = 44,
bits_ty = u64,
bits_ty_signed = i64,
double_ty = u128,
float_ty = f64,
is_nan = crate::expect_failed("passed NaN to `time::Duration::seconds_f64`"),
is_overflow = crate::expect_failed("overflow constructing `time::Duration`"),
)
}

time/time/src/duration.rs

Lines 441 to 453 in 6248992

/// Create a new `Duration` with the given number of days. Equivalent to
/// `Duration::seconds(days * 86_400)`.
///
/// ```rust
/// # use time::{Duration, ext::NumericalDuration};
/// assert_eq!(Duration::days(1), 86_400.seconds());
/// ```
pub const fn days(days: i64) -> Self {
Self::seconds(expect_opt!(
days.checked_mul(Second.per(Day) as _),
"overflow constructing `time::Duration`"
))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: documentationE-help-wanted 📣Community assistance is desired and welcomed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions