Skip to content

Commit 74be6f7

Browse files
committed
cast_ptr_alignment: move the regular check into the if
this allows reusing `cast_from` and `cast_to` one possible problem is that the `if` has an additional `is_hir_ty_cfg_dependant` check which the let-chain of the original `check` didn't have.. but maybe this is actually more correct
1 parent 9acb48d commit 74be6f7

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

clippy_lints/src/casts/cast_ptr_alignment.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,8 @@ use rustc_middle::ty::{self, Ty};
88

99
use super::CAST_PTR_ALIGNMENT;
1010

11-
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
12-
if let ExprKind::Cast(cast_expr, cast_to) = expr.kind {
13-
if is_hir_ty_cfg_dependant(cx, cast_to) {
14-
return;
15-
}
16-
let (cast_from, cast_to) = (
17-
cx.typeck_results().expr_ty(cast_expr),
18-
cx.typeck_results().expr_ty(expr),
19-
);
20-
lint_cast_ptr_alignment(cx, expr, cast_from, cast_to);
21-
}
11+
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>) {
12+
lint_cast_ptr_alignment(cx, expr, cast_from, cast_to);
2213
}
2314

2415
pub(super) fn check_cast_method(cx: &LateContext<'_>, expr: &Expr<'_>) {

clippy_lints/src/casts/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
873873
}
874874
char_lit_as_u8::check(cx, expr, cast_from_expr, cast_to);
875875
cast_slice_from_raw_parts::check(cx, expr, cast_from_expr, cast_to, self.msrv);
876+
cast_ptr_alignment::check(cx, expr, cast_from, cast_to);
876877
ptr_cast_constness::check(cx, expr, cast_from_expr, cast_from, cast_to, self.msrv);
877878
as_ptr_cast_mut::check(cx, expr, cast_from_expr, cast_to);
878879
fn_to_numeric_cast_any::check(cx, expr, cast_from_expr, cast_from, cast_to);
@@ -914,7 +915,6 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
914915
if self.msrv.meets(cx, msrvs::PTR_SLICE_RAW_PARTS) {
915916
cast_slice_from_raw_parts::check_implicit_cast(cx, expr);
916917
}
917-
cast_ptr_alignment::check(cx, expr);
918918
cast_ptr_alignment::check_cast_method(cx, expr);
919919
ptr_as_ptr::check(cx, expr, self.msrv);
920920
cast_slice_different_sizes::check(cx, expr, self.msrv);

0 commit comments

Comments
 (0)