Fix cast_abs_to_unsigned generates non-compiling code when original code is in parens
This commit is contained in:
parent
580f642cfa
commit
0e1d65850a
@ -37,7 +37,7 @@ pub(super) fn check(
|
||||
span,
|
||||
&format!("casting the result of `{cast_from}::abs()` to {cast_to}"),
|
||||
"replace with",
|
||||
format!("{}.unsigned_abs()", Sugg::hir(cx, &args[0], "..")),
|
||||
format!("{}.unsigned_abs()", Sugg::hir(cx, &args[0], "..").maybe_par()),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
|
@ -26,4 +26,6 @@ fn main() {
|
||||
let _ = a.unsigned_abs() as u32;
|
||||
let _ = a.unsigned_abs() as u64;
|
||||
let _ = a.unsigned_abs() as u128;
|
||||
|
||||
let _ = (x as i64 - y as i64).unsigned_abs() as u32;
|
||||
}
|
||||
|
@ -26,4 +26,6 @@ fn main() {
|
||||
let _ = a.abs() as u32;
|
||||
let _ = a.abs() as u64;
|
||||
let _ = a.abs() as u128;
|
||||
|
||||
let _ = (x as i64 - y as i64).abs() as u32;
|
||||
}
|
||||
|
@ -96,5 +96,11 @@ error: casting the result of `isize::abs()` to u128
|
||||
LL | let _ = a.abs() as u128;
|
||||
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
|
||||
|
||||
error: aborting due to 16 previous errors
|
||||
error: casting the result of `i64::abs()` to u32
|
||||
--> $DIR/cast_abs_to_unsigned.rs:30:13
|
||||
|
|
||||
LL | let _ = (x as i64 - y as i64).abs() as u32;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `(x as i64 - y as i64).unsigned_abs()`
|
||||
|
||||
error: aborting due to 17 previous errors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user