2023-04-23 06:03:09 -05:00
|
|
|
//@run-rustfix
|
2022-01-27 08:12:45 -06:00
|
|
|
#![allow(dead_code, clippy::needless_borrow)]
|
2019-01-13 05:06:28 -06:00
|
|
|
#![warn(clippy::duration_subsec)]
|
|
|
|
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let dur = Duration::new(5, 0);
|
|
|
|
|
|
|
|
let bad_millis_1 = dur.subsec_millis();
|
|
|
|
let bad_millis_2 = dur.subsec_millis();
|
|
|
|
let good_millis = dur.subsec_millis();
|
|
|
|
assert_eq!(bad_millis_1, good_millis);
|
|
|
|
assert_eq!(bad_millis_2, good_millis);
|
|
|
|
|
|
|
|
let bad_micros = dur.subsec_micros();
|
|
|
|
let good_micros = dur.subsec_micros();
|
|
|
|
assert_eq!(bad_micros, good_micros);
|
|
|
|
|
|
|
|
// Handle refs
|
|
|
|
let _ = (&dur).subsec_micros();
|
|
|
|
|
|
|
|
// Handle constants
|
|
|
|
const NANOS_IN_MICRO: u32 = 1_000;
|
|
|
|
let _ = dur.subsec_micros();
|
|
|
|
|
|
|
|
// Other literals aren't linted
|
|
|
|
let _ = dur.subsec_nanos() / 699;
|
|
|
|
}
|