mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-08 09:38:26 +03:00
fix: unchecked_time_subtraction wrongly unmangled macros
This commit is contained in:
@@ -178,8 +178,9 @@ fn print_unchecked_duration_subtraction_sugg(
|
||||
// avoid suggestions
|
||||
if !is_chained_time_subtraction(cx, left_expr) {
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
let left_sugg = Sugg::hir_with_applicability(cx, left_expr, "<left>", &mut applicability);
|
||||
let right_sugg = Sugg::hir_with_applicability(cx, right_expr, "<right>", &mut applicability);
|
||||
let left_sugg = Sugg::hir_with_context(cx, left_expr, expr.span.ctxt(), "<left>", &mut applicability);
|
||||
let right_sugg =
|
||||
Sugg::hir_with_context(cx, right_expr, expr.span.ctxt(), "<right>", &mut applicability);
|
||||
|
||||
diag.span_suggestion(
|
||||
expr.span,
|
||||
|
||||
@@ -45,3 +45,18 @@ fn issue16230() {
|
||||
let _ = Duration::ZERO.checked_sub(Duration::MAX).unwrap();
|
||||
//~^ unchecked_time_subtraction
|
||||
}
|
||||
|
||||
fn issue16234() {
|
||||
use std::ops::Sub as _;
|
||||
|
||||
macro_rules! duration {
|
||||
($secs:expr) => {
|
||||
Duration::from_secs($secs)
|
||||
};
|
||||
}
|
||||
|
||||
duration!(0).checked_sub(duration!(1)).unwrap();
|
||||
//~^ unchecked_time_subtraction
|
||||
let _ = duration!(0).checked_sub(duration!(1)).unwrap();
|
||||
//~^ unchecked_time_subtraction
|
||||
}
|
||||
|
||||
@@ -45,3 +45,18 @@ fn issue16230() {
|
||||
let _ = Duration::ZERO - Duration::MAX;
|
||||
//~^ unchecked_time_subtraction
|
||||
}
|
||||
|
||||
fn issue16234() {
|
||||
use std::ops::Sub as _;
|
||||
|
||||
macro_rules! duration {
|
||||
($secs:expr) => {
|
||||
Duration::from_secs($secs)
|
||||
};
|
||||
}
|
||||
|
||||
duration!(0).sub(duration!(1));
|
||||
//~^ unchecked_time_subtraction
|
||||
let _ = duration!(0) - duration!(1);
|
||||
//~^ unchecked_time_subtraction
|
||||
}
|
||||
|
||||
@@ -61,5 +61,17 @@ error: unchecked subtraction of a `Duration`
|
||||
LL | let _ = Duration::ZERO - Duration::MAX;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Duration::ZERO.checked_sub(Duration::MAX).unwrap()`
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
error: unchecked subtraction of a `Duration`
|
||||
--> tests/ui/unchecked_time_subtraction.rs:58:5
|
||||
|
|
||||
LL | duration!(0).sub(duration!(1));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `duration!(0).checked_sub(duration!(1)).unwrap()`
|
||||
|
||||
error: unchecked subtraction of a `Duration`
|
||||
--> tests/ui/unchecked_time_subtraction.rs:60:13
|
||||
|
|
||||
LL | let _ = duration!(0) - duration!(1);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `duration!(0).checked_sub(duration!(1)).unwrap()`
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
|
||||
|
||||
Reference in New Issue
Block a user