RS.CLIPPY.UNCHECKED_DURATION_SUBTRACTION

Finds unchecked subtraction of a 'Duration' from an 'Instant'

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: unchecked_duration_subtraction. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Lints subtraction between an Instant and a Duration.

Why is this bad?

Unchecked subtraction could cause underflow on certain platforms, leading to unintentional panics.

Example

let time_passed = Instant::now() - Duration::from_secs(5);

Use instead:

let time_passed = Instant::now().checked_sub(Duration::from_secs(5));

Configuration

  • msrv: The minimum rust version that the project supports. Defaults to the rust-version field in Cargo.toml

    (default: current version)