Skip to content

duration_suboptimal_units should not trigger on small values #16532

@ensc

Description

@ensc

Summary

The duration_suboptimal_units lint triggers on

Duration::from_millis(1_000);

suggesting

Duration::from_secs(1)

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)

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't havegood first issueThese issues are a good way to get started with Clippy

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions