mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
Auto merge of #9266 - alex-semenyuk:cast_abs_to_unsigned_paren_fix, r=Jarcho
Fix cast_abs_to_unsigned with code in parens Close #9185 changelog: none
This commit is contained in:
commit
2dc7d2f7f5
4 changed files with 12 additions and 2 deletions
|
@ -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…
Reference in a new issue