Skip to content

Commit 9acb48d

Browse files
committed
cast_ptr_alignment: move the .cast() check into a separate fn
1 parent 2427ec2 commit 9acb48d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

clippy_lints/src/casts/cast_ptr_alignment.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
1818
cx.typeck_results().expr_ty(expr),
1919
);
2020
lint_cast_ptr_alignment(cx, expr, cast_from, cast_to);
21-
} else if let ExprKind::MethodCall(method_path, self_arg, [], _) = &expr.kind
21+
}
22+
}
23+
24+
pub(super) fn check_cast_method(cx: &LateContext<'_>, expr: &Expr<'_>) {
25+
if let ExprKind::MethodCall(method_path, self_arg, [], _) = &expr.kind
2226
&& method_path.ident.name == sym::cast
2327
&& let Some(generic_args) = method_path.args
2428
&& let [GenericArg::Type(cast_to)] = generic_args.args

clippy_lints/src/casts/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
915915
cast_slice_from_raw_parts::check_implicit_cast(cx, expr);
916916
}
917917
cast_ptr_alignment::check(cx, expr);
918+
cast_ptr_alignment::check_cast_method(cx, expr);
918919
ptr_as_ptr::check(cx, expr, self.msrv);
919920
cast_slice_different_sizes::check(cx, expr, self.msrv);
920921
ptr_cast_constness::check_null_ptr_cast_method(cx, expr);

0 commit comments

Comments
 (0)