| #![warn(clippy::unchecked_time_subtraction)] |
| |
| use std::time::{Duration, Instant}; |
| |
| fn main() { |
| let _first = Instant::now(); |
| let second = Duration::from_secs(3); |
| |
| let _ = _first.checked_sub(second).unwrap(); |
| //~^ unchecked_time_subtraction |
| |
| let _ = Instant::now().checked_sub(Duration::from_secs(5)).unwrap(); |
| //~^ unchecked_time_subtraction |
| |
| let _ = _first.checked_sub(Duration::from_secs(5)).unwrap(); |
| //~^ unchecked_time_subtraction |
| |
| let _ = Instant::now().checked_sub(second).unwrap(); |
| //~^ unchecked_time_subtraction |
| |
| // Duration - Duration cases |
| let dur1 = Duration::from_secs(5); |
| let dur2 = Duration::from_secs(3); |
| |
| let _ = dur1.checked_sub(dur2).unwrap(); |
| //~^ unchecked_time_subtraction |
| |
| let _ = Duration::from_secs(10).checked_sub(Duration::from_secs(5)).unwrap(); |
| //~^ unchecked_time_subtraction |
| |
| let _ = second.checked_sub(dur1).unwrap(); |
| //~^ unchecked_time_subtraction |
| |
| // Duration multiplication and subtraction |
| let _ = (2 * dur1).checked_sub(dur2).unwrap(); |
| //~^ unchecked_time_subtraction |
| } |