diff options
| author | Ada Alakbarova <ada.alakbarova@proton.me> | 2025-08-13 14:47:29 +0200 |
|---|---|---|
| committer | Ada Alakbarova <ada.alakbarova@proton.me> | 2025-08-24 08:25:02 +0200 |
| commit | 74be6f769ab3a503ed01dee59b459027dbced016 (patch) | |
| tree | 091f8c79fd64a1af459849b998ef00082f735ef5 | |
| parent | 9acb48dbbe4bdb5ab7049e99a2b13c4aebc45981 (diff) | |
| download | rust-74be6f769ab3a503ed01dee59b459027dbced016.tar.gz rust-74be6f769ab3a503ed01dee59b459027dbced016.zip | |
`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
| -rw-r--r-- | clippy_lints/src/casts/cast_ptr_alignment.rs | 13 | ||||
| -rw-r--r-- | clippy_lints/src/casts/mod.rs | 2 |
2 files changed, 3 insertions, 12 deletions
diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs index fd8302e4417..d78da9396fa 100644 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -8,17 +8,8 @@ use rustc_middle::ty::{self, Ty}; use super::CAST_PTR_ALIGNMENT; -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { - if let ExprKind::Cast(cast_expr, cast_to) = expr.kind { - if is_hir_ty_cfg_dependant(cx, cast_to) { - return; - } - let (cast_from, cast_to) = ( - cx.typeck_results().expr_ty(cast_expr), - cx.typeck_results().expr_ty(expr), - ); - lint_cast_ptr_alignment(cx, expr, cast_from, cast_to); - } +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>) { + lint_cast_ptr_alignment(cx, expr, cast_from, cast_to); } pub(super) fn check_cast_method(cx: &LateContext<'_>, expr: &Expr<'_>) { diff --git a/clippy_lints/src/casts/mod.rs b/clippy_lints/src/casts/mod.rs index 976e0d19657..94940b32f27 100644 --- a/clippy_lints/src/casts/mod.rs +++ b/clippy_lints/src/casts/mod.rs @@ -873,6 +873,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts { } char_lit_as_u8::check(cx, expr, cast_from_expr, cast_to); cast_slice_from_raw_parts::check(cx, expr, cast_from_expr, cast_to, self.msrv); + cast_ptr_alignment::check(cx, expr, cast_from, cast_to); ptr_cast_constness::check(cx, expr, cast_from_expr, cast_from, cast_to, self.msrv); as_ptr_cast_mut::check(cx, expr, cast_from_expr, cast_to); 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 { if self.msrv.meets(cx, msrvs::PTR_SLICE_RAW_PARTS) { 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); |
