rust-lang / rust-lang/rust-clippy

absurd extreme comparisons not working for std::time::Duration

Open
#14,524 1 comment 0 reactions 1 assignee View on GitHub

@alex-semenyuk is already working on this.

Since Apr 22, 2025.

C-bug I-false-negative
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

Duration values cannot be negative under any circumstance, so it's not useful to check if a Duration is less than zero. Please make sure all Durations which can be const evaluated to zero, are treated as zero for the purposes of this lint.

Lint Name

absurd_extreme_comparisons

Reproducer

I tried this code:

if duration < Duration::from_secs(0) {
    // ...
}

I expected to see this happen: absurd_extreme_comparisons lint activates

Instead, this happened: no lint is triggered, code is accepted as is

Version
rustc 1.85.0 (4d91de4e4 2025-02-17)
binary: rustc
commit-hash: 4d91de4e48198da2e33413efdcd9cd2cc0c46688
commit-date: 2025-02-17
host: aarch64-unknown-linux-gnu
release: 1.85.0
LLVM version: 19.1.7

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.