Skip to content

Commit ac3c58d

Browse files
committed
duration_suboptimal_units: print the complete method name in the suggestion
1 parent 2b41e36 commit ac3c58d

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

clippy_lints/src/duration_suboptimal_units.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl LateLintPass<'_> for DurationSuboptimalUnits {
9999
(arg.span, promoted_value.to_string()),
100100
];
101101
diag.multipart_suggestion(
102-
format!("try using {promoted_constructor}"),
102+
format!("try using `Duration::{promoted_constructor}`"),
103103
suggestions,
104104
Applicability::MachineApplicable,
105105
);

tests/ui/duration_suboptimal_units.stderr

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | let dur = Duration::from_secs(60);
66
|
77
= note: `-D clippy::duration-suboptimal-units` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::duration_suboptimal_units)]`
9-
help: try using from_mins
9+
help: try using `Duration::from_mins`
1010
|
1111
LL - let dur = Duration::from_secs(60);
1212
LL + let dur = Duration::from_mins(1);
@@ -18,7 +18,7 @@ error: constructing a `Duration` using a smaller unit when a larger unit would b
1818
LL | let dur = Duration::from_secs(180);
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^
2020
|
21-
help: try using from_mins
21+
help: try using `Duration::from_mins`
2222
|
2323
LL - let dur = Duration::from_secs(180);
2424
LL + let dur = Duration::from_mins(3);
@@ -30,7 +30,7 @@ error: constructing a `Duration` using a smaller unit when a larger unit would b
3030
LL | let dur = Duration::from_secs(10 * 60);
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3232
|
33-
help: try using from_mins
33+
help: try using `Duration::from_mins`
3434
|
3535
LL - let dur = Duration::from_secs(10 * 60);
3636
LL + let dur = Duration::from_mins(10);
@@ -42,7 +42,7 @@ error: constructing a `Duration` using a smaller unit when a larger unit would b
4242
LL | let dur = Duration::from_mins(24 * 60);
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4444
|
45-
help: try using from_hours
45+
help: try using `Duration::from_hours`
4646
|
4747
LL - let dur = Duration::from_mins(24 * 60);
4848
LL + let dur = Duration::from_hours(24);
@@ -54,7 +54,7 @@ error: constructing a `Duration` using a smaller unit when a larger unit would b
5454
LL | let dur = Duration::from_millis(5_000);
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5656
|
57-
help: try using from_secs
57+
help: try using `Duration::from_secs`
5858
|
5959
LL - let dur = Duration::from_millis(5_000);
6060
LL + let dur = Duration::from_secs(5);
@@ -66,7 +66,7 @@ error: constructing a `Duration` using a smaller unit when a larger unit would b
6666
LL | let dur = Duration::from_nanos(13 * 60 * 60 * 1_000 * 1_000 * 1_000);
6767
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6868
|
69-
help: try using from_hours
69+
help: try using `Duration::from_hours`
7070
|
7171
LL - let dur = Duration::from_nanos(13 * 60 * 60 * 1_000 * 1_000 * 1_000);
7272
LL + let dur = Duration::from_hours(13);
@@ -78,7 +78,7 @@ error: constructing a `Duration` using a smaller unit when a larger unit would b
7878
LL | let dur = Duration::from_millis(5_000);
7979
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8080
|
81-
help: try using from_secs
81+
help: try using `Duration::from_secs`
8282
|
8383
LL - let dur = Duration::from_millis(5_000);
8484
LL + let dur = Duration::from_secs(5);
@@ -90,7 +90,7 @@ error: constructing a `Duration` using a smaller unit when a larger unit would b
9090
LL | let dur = Duration::from_secs(180);
9191
| ^^^^^^^^^^^^^^^^^^^^^^^^
9292
|
93-
help: try using from_mins
93+
help: try using `Duration::from_mins`
9494
|
9595
LL - let dur = Duration::from_secs(180);
9696
LL + let dur = Duration::from_mins(3);
@@ -102,7 +102,7 @@ error: constructing a `Duration` using a smaller unit when a larger unit would b
102102
LL | let dur = Duration::from_mins(24 * 60);
103103
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
104104
|
105-
help: try using from_hours
105+
help: try using `Duration::from_hours`
106106
|
107107
LL - let dur = Duration::from_mins(24 * 60);
108108
LL + let dur = Duration::from_hours(24);
@@ -114,7 +114,7 @@ error: constructing a `Duration` using a smaller unit when a larger unit would b
114114
LL | std::time::Duration::from_secs(60);
115115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
116116
|
117-
help: try using from_mins
117+
help: try using `Duration::from_mins`
118118
|
119119
LL - std::time::Duration::from_secs(60);
120120
LL + std::time::Duration::from_mins(1);
@@ -126,7 +126,7 @@ error: constructing a `Duration` using a smaller unit when a larger unit would b
126126
LL | assert_eq!(Duration::from_secs(3_600), Duration::from_mins(6));
127127
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
128128
|
129-
help: try using from_hours
129+
help: try using `Duration::from_hours`
130130
|
131131
LL - assert_eq!(Duration::from_secs(3_600), Duration::from_mins(6));
132132
LL + assert_eq!(Duration::from_hours(1), Duration::from_mins(6));
@@ -142,7 +142,7 @@ LL | let dur = mac!(duration);
142142
| -------------- in this macro invocation
143143
|
144144
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
145-
help: try using from_mins
145+
help: try using `Duration::from_mins`
146146
|
147147
LL - Duration::from_secs(300)
148148
LL + Duration::from_mins(5)
@@ -154,7 +154,7 @@ error: constructing a `Duration` using a smaller unit when a larger unit would b
154154
LL | _ = Duration::from_secs(67_768_040_922_076_800);
155155
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
156156
|
157-
help: try using from_hours
157+
help: try using `Duration::from_hours`
158158
|
159159
LL - _ = Duration::from_secs(67_768_040_922_076_800);
160160
LL + _ = Duration::from_hours(18824455811688);

tests/ui/duration_suboptimal_units_days_weeks.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | let dur = Duration::from_secs(60);
66
|
77
= note: `-D clippy::duration-suboptimal-units` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::duration_suboptimal_units)]`
9-
help: try using from_mins
9+
help: try using `Duration::from_mins`
1010
|
1111
LL - let dur = Duration::from_secs(60);
1212
LL + let dur = Duration::from_mins(1);
@@ -18,7 +18,7 @@ error: constructing a `Duration` using a smaller unit when a larger unit would b
1818
LL | let dur = Duration::from_hours(24);
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^
2020
|
21-
help: try using from_days
21+
help: try using `Duration::from_days`
2222
|
2323
LL - let dur = Duration::from_hours(24);
2424
LL + let dur = Duration::from_days(1);
@@ -30,7 +30,7 @@ error: constructing a `Duration` using a smaller unit when a larger unit would b
3030
LL | let dur = Duration::from_nanos(13 * 7 * 24 * 60 * 60 * 1_000 * 1_000 * 1_000);
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3232
|
33-
help: try using from_weeks
33+
help: try using `Duration::from_weeks`
3434
|
3535
LL - let dur = Duration::from_nanos(13 * 7 * 24 * 60 * 60 * 1_000 * 1_000 * 1_000);
3636
LL + let dur = Duration::from_weeks(13);

0 commit comments

Comments
 (0)