Summary
The duration_suboptimal_units lint triggers on
Duration::from_millis(1_000);
suggesting
but this makes quick adjustments harder. E.g. Changing 1_000 to 1_200 requires modifying both the function name and the value.
I suggest that the lint triggers only when the target value exceeds a certain threshold (e.g. 10).
Rationale
-
code becomes inconsistent; having
let _ = Duration::from_secs(210);
let _ = Duration::from_mins(3);
let _ = Duration::from_secs(150);
let _ = Duration::from_millis(800);
let _ = Duration::from_secs(1);
let _ = Duration::from_millis(1_100);
breaks readability. Readers must mentally convert between units.
-
minimal adaptions of the duration require (non-trivial) code changes
-
from_secs(1) is not easier to read than from_millis(1_000)
-
code smell like from_millis(1_001) to workaround the lint
Lint Name
duration_suboptimal_units
Version
clippy 0.1.95 (a293cc4af8 2026-01-30)
Summary
The
duration_suboptimal_unitslint triggers onsuggesting
but this makes quick adjustments harder. E.g. Changing 1_000 to 1_200 requires modifying both the function name and the value.
I suggest that the lint triggers only when the target value exceeds a certain threshold (e.g. 10).
Rationale
code becomes inconsistent; having
breaks readability. Readers must mentally convert between units.
minimal adaptions of the duration require (non-trivial) code changes
from_secs(1)is not easier to read thanfrom_millis(1_000)code smell like
from_millis(1_001)to workaround the lintLint Name
duration_suboptimal_unitsVersion