Skip to content

Commit ea45686

Browse files
authored
Add MSRV-based tests to duration_suboptimal_units lint (rust-lang#16526)
Noticed because of rust-lang#16525 changelog: none
2 parents 739f462 + 5db9e1c commit ea45686

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

tests/ui/duration_suboptimal_units.fixed

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,14 @@ fn issue16457() {
9494
// Methods taking something else than `u64` are not covered
9595
_ = Duration::from_nanos_u128(1 << 90);
9696
}
97+
98+
#[clippy::msrv = "1.90"]
99+
fn insufficient_msrv() {
100+
_ = Duration::from_secs(67_768_040_922_076_800);
101+
}
102+
103+
#[clippy::msrv = "1.91"]
104+
fn sufficient_msrv() {
105+
_ = Duration::from_hours(18824455811688);
106+
//~^ duration_suboptimal_units
107+
}

tests/ui/duration_suboptimal_units.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,14 @@ fn issue16457() {
9494
// Methods taking something else than `u64` are not covered
9595
_ = Duration::from_nanos_u128(1 << 90);
9696
}
97+
98+
#[clippy::msrv = "1.90"]
99+
fn insufficient_msrv() {
100+
_ = Duration::from_secs(67_768_040_922_076_800);
101+
}
102+
103+
#[clippy::msrv = "1.91"]
104+
fn sufficient_msrv() {
105+
_ = Duration::from_secs(67_768_040_922_076_800);
106+
//~^ duration_suboptimal_units
107+
}

tests/ui/duration_suboptimal_units.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,17 @@ LL - Duration::from_secs(300)
148148
LL + Duration::from_mins(5)
149149
|
150150

151-
error: aborting due to 12 previous errors
151+
error: constructing a `Duration` using a smaller unit when a larger unit would be more readable
152+
--> tests/ui/duration_suboptimal_units.rs:105:9
153+
|
154+
LL | _ = Duration::from_secs(67_768_040_922_076_800);
155+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
156+
|
157+
help: try using from_hours
158+
|
159+
LL - _ = Duration::from_secs(67_768_040_922_076_800);
160+
LL + _ = Duration::from_hours(18824455811688);
161+
|
162+
163+
error: aborting due to 13 previous errors
152164

0 commit comments

Comments
 (0)