Skip to content

Commit 2dc7d2f

Browse files
committed
Auto merge of rust-lang#9266 - alex-semenyuk:cast_abs_to_unsigned_paren_fix, r=Jarcho
Fix cast_abs_to_unsigned with code in parens Close rust-lang#9185 changelog: none
2 parents 7177746 + 0e1d658 commit 2dc7d2f

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

clippy_lints/src/casts/cast_abs_to_unsigned.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub(super) fn check(
3737
span,
3838
&format!("casting the result of `{cast_from}::abs()` to {cast_to}"),
3939
"replace with",
40-
format!("{}.unsigned_abs()", Sugg::hir(cx, &args[0], "..")),
40+
format!("{}.unsigned_abs()", Sugg::hir(cx, &args[0], "..").maybe_par()),
4141
Applicability::MachineApplicable,
4242
);
4343
}

tests/ui/cast_abs_to_unsigned.fixed

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ fn main() {
2626
let _ = a.unsigned_abs() as u32;
2727
let _ = a.unsigned_abs() as u64;
2828
let _ = a.unsigned_abs() as u128;
29+
30+
let _ = (x as i64 - y as i64).unsigned_abs() as u32;
2931
}

tests/ui/cast_abs_to_unsigned.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ fn main() {
2626
let _ = a.abs() as u32;
2727
let _ = a.abs() as u64;
2828
let _ = a.abs() as u128;
29+
30+
let _ = (x as i64 - y as i64).abs() as u32;
2931
}

tests/ui/cast_abs_to_unsigned.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,11 @@ error: casting the result of `isize::abs()` to u128
9696
LL | let _ = a.abs() as u128;
9797
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
9898

99-
error: aborting due to 16 previous errors
99+
error: casting the result of `i64::abs()` to u32
100+
--> $DIR/cast_abs_to_unsigned.rs:30:13
101+
|
102+
LL | let _ = (x as i64 - y as i64).abs() as u32;
103+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `(x as i64 - y as i64).unsigned_abs()`
104+
105+
error: aborting due to 17 previous errors
100106

0 commit comments

Comments
 (0)