about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAda Alakbarova <ada.alakbarova@proton.me>2025-08-13 14:42:42 +0200
committerAda Alakbarova <ada.alakbarova@proton.me>2025-08-24 08:23:01 +0200
commit9acb48dbbe4bdb5ab7049e99a2b13c4aebc45981 (patch)
treeeb7b47e725a5551c42de8a3d74b76ea87ef46784
parent2427ec250a0a6b3c9d03bd45b1a71e62a6a6b060 (diff)
downloadrust-9acb48dbbe4bdb5ab7049e99a2b13c4aebc45981.tar.gz
rust-9acb48dbbe4bdb5ab7049e99a2b13c4aebc45981.zip
`cast_ptr_alignment`: move the `.cast()` check into a separate fn
-rw-r--r--clippy_lints/src/casts/cast_ptr_alignment.rs6
-rw-r--r--clippy_lints/src/casts/mod.rs1
2 files changed, 6 insertions, 1 deletions
diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs
index 5e206165842..fd8302e4417 100644
--- a/clippy_lints/src/casts/cast_ptr_alignment.rs
+++ b/clippy_lints/src/casts/cast_ptr_alignment.rs
@@ -18,7 +18,11 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
             cx.typeck_results().expr_ty(expr),
         );
         lint_cast_ptr_alignment(cx, expr, cast_from, cast_to);
-    } else if let ExprKind::MethodCall(method_path, self_arg, [], _) = &expr.kind
+    }
+}
+
+pub(super) fn check_cast_method(cx: &LateContext<'_>, expr: &Expr<'_>) {
+    if let ExprKind::MethodCall(method_path, self_arg, [], _) = &expr.kind
         && method_path.ident.name == sym::cast
         && let Some(generic_args) = method_path.args
         && let [GenericArg::Type(cast_to)] = generic_args.args
diff --git a/clippy_lints/src/casts/mod.rs b/clippy_lints/src/casts/mod.rs
index 58de51a3229..976e0d19657 100644
--- a/clippy_lints/src/casts/mod.rs
+++ b/clippy_lints/src/casts/mod.rs
@@ -915,6 +915,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
             cast_slice_from_raw_parts::check_implicit_cast(cx, expr);
         }
         cast_ptr_alignment::check(cx, expr);
+        cast_ptr_alignment::check_cast_method(cx, expr);
         ptr_as_ptr::check(cx, expr, self.msrv);
         cast_slice_different_sizes::check(cx, expr, self.msrv);
         ptr_cast_constness::check_null_ptr_cast_method(cx, expr);