diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 6a105a87e623..be23af41eb59 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -1020,12 +1020,12 @@ fn check_loss_of_sign(cx: &LateContext<'_, '_>, expr: &Expr, op: &Expr, cast_fro } } - // don't lint for the result of `abs` + // don't lint for the result of `abs` & `checked_abs` // `abs` is an inherent impl of `i{N}`, so a method call with ident `abs` will always // resolve to that spesific method if_chain! { if let ExprKind::MethodCall(ref path, _, _) = op.kind; - if path.ident.name.as_str() == "abs"; + if ["abs", "checked_abs"].contains(path.ident.name); then { return } diff --git a/tests/ui/cast.rs b/tests/ui/cast.rs index 80329a52c2d0..b8ada45eeaaf 100644 --- a/tests/ui/cast.rs +++ b/tests/ui/cast.rs @@ -47,4 +47,9 @@ fn main() { (-1i32).abs() as u32; (-1i64).abs() as u64; (-1isize).abs() as usize; + (-1i8).checked_abs().unwrap() as u8; + (-1i16).checked_abs().unwrap() as u16; + (-1i32).checked_abs().unwrap() as u32; + (-1i64).checked_abs().unwrap() as u64; + (-1isize).checked_abs().unwrap() as usize; }