Skip to content

Commit b7224f5

Browse files
committed
Use more explanatory comment
1 parent 642ce22 commit b7224f5

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

clippy_lints/src/duration_suboptimal_units.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ impl LateLintPass<'_> for DurationSuboptimalUnits {
8989
// There is no need to promote e.g. 0 seconds to 0 hours
9090
&& value != 0
9191
&& let Some((promoted_constructor, promoted_value)) = self.promote(cx, func_name.ident.name, value)
92-
// Does not promote for literals with resulting values <=10
92+
// For plain integer literals, only lint if the promoted value is large enough.
93+
// Small promoted values (e.g. `from_millis(1_000)` -> `from_secs(1)`) are not
94+
// necessarily more readable, and keeping the smaller unit makes quick adjustments
95+
// easier (e.g. changing 1_000 to 1_200 without also changing the function name).
96+
// For expressions (e.g. `10 * 60`), always lint since the expression already
97+
// signals intent to compute a converted value.
9398
&& (!matches!(arg.kind, ExprKind::Lit(_)) || promoted_value > 10)
9499
{
95100
span_lint_and_then(

0 commit comments

Comments
 (0)