rust-lang / rust-lang/rust-clippy
absurd extreme comparisons not working for std::time::Duration
Open
@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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.