diff --git a/clippy_lints/src/instant_subtraction.rs b/clippy_lints/src/instant_subtraction.rs index c039f1b5c6a..d83beb622cf 100644 --- a/clippy_lints/src/instant_subtraction.rs +++ b/clippy_lints/src/instant_subtraction.rs @@ -174,7 +174,7 @@ fn print_unchecked_duration_subtraction_sugg( expr.span, "unchecked subtraction of a 'Duration' from an 'Instant'", "try", - format!("{left_expr}.checked_sub({right_expr}).unwrap();"), + format!("{left_expr}.checked_sub({right_expr}).unwrap()"), applicability, ); } diff --git a/tests/ui/unchecked_duration_subtraction.fixed b/tests/ui/unchecked_duration_subtraction.fixed index bcc231d93b1..a0e49a8beb1 100644 --- a/tests/ui/unchecked_duration_subtraction.fixed +++ b/tests/ui/unchecked_duration_subtraction.fixed @@ -7,11 +7,11 @@ fn main() { let _first = Instant::now(); let second = Duration::from_secs(3); - let _ = _first.checked_sub(second).unwrap();; + let _ = _first.checked_sub(second).unwrap(); - let _ = Instant::now().checked_sub(Duration::from_secs(5)).unwrap();; + let _ = Instant::now().checked_sub(Duration::from_secs(5)).unwrap(); - let _ = _first.checked_sub(Duration::from_secs(5)).unwrap();; + let _ = _first.checked_sub(Duration::from_secs(5)).unwrap(); - let _ = Instant::now().checked_sub(second).unwrap();; + let _ = Instant::now().checked_sub(second).unwrap(); } diff --git a/tests/ui/unchecked_duration_subtraction.stderr b/tests/ui/unchecked_duration_subtraction.stderr index b949dbf701a..a2e0aa1d7c0 100644 --- a/tests/ui/unchecked_duration_subtraction.stderr +++ b/tests/ui/unchecked_duration_subtraction.stderr @@ -2,7 +2,7 @@ error: unchecked subtraction of a 'Duration' from an 'Instant' --> $DIR/unchecked_duration_subtraction.rs:10:13 | LL | let _ = _first - second; - | ^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(second).unwrap();` + | ^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(second).unwrap()` | = note: `-D clippy::unchecked-duration-subtraction` implied by `-D warnings` @@ -10,19 +10,19 @@ error: unchecked subtraction of a 'Duration' from an 'Instant' --> $DIR/unchecked_duration_subtraction.rs:12:13 | LL | let _ = Instant::now() - Duration::from_secs(5); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(Duration::from_secs(5)).unwrap();` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(Duration::from_secs(5)).unwrap()` error: unchecked subtraction of a 'Duration' from an 'Instant' --> $DIR/unchecked_duration_subtraction.rs:14:13 | LL | let _ = _first - Duration::from_secs(5); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(Duration::from_secs(5)).unwrap();` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(Duration::from_secs(5)).unwrap()` error: unchecked subtraction of a 'Duration' from an 'Instant' --> $DIR/unchecked_duration_subtraction.rs:16:13 | LL | let _ = Instant::now() - second; - | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(second).unwrap();` + | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(second).unwrap()` error: aborting due to 4 previous errors