Skip to content

Commit e916447

Browse files
committed
Clean up needlessly complex equality check
1 parent 55286e7 commit e916447

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

clippy_lints/src/casts/ptr_as_ptr.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clippy_utils::msrvs::{self, Msrv};
44
use clippy_utils::source::snippet_with_applicability;
55
use clippy_utils::sugg::Sugg;
66
use rustc_errors::Applicability;
7-
use rustc_hir::{Expr, ExprKind, Mutability, QPath, TyKind};
7+
use rustc_hir::{Expr, ExprKind, QPath, TyKind};
88
use rustc_lint::LateContext;
99
use rustc_middle::ty;
1010
use rustc_span::{Span, sym};
@@ -31,8 +31,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: Msrv)
3131
&& let (cast_from, cast_to) = (cx.typeck_results().expr_ty(cast_expr), cx.typeck_results().expr_ty(expr))
3232
&& let ty::RawPtr(_, from_mutbl) = cast_from.kind()
3333
&& let ty::RawPtr(to_pointee_ty, to_mutbl) = cast_to.kind()
34-
&& matches!((from_mutbl, to_mutbl),
35-
(Mutability::Not, Mutability::Not) | (Mutability::Mut, Mutability::Mut))
34+
&& from_mutbl == to_mutbl
3635
// The `U` in `pointer::cast` have to be `Sized`
3736
// as explained here: https://github.com/rust-lang/rust/issues/60602.
3837
&& to_pointee_ty.is_sized(cx.tcx, cx.typing_env())

clippy_lints/src/casts/ptr_cast_constness.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::msrvs::{self, Msrv};
33
use clippy_utils::sugg::Sugg;
44
use clippy_utils::{std_or_core, sym};
55
use rustc_errors::Applicability;
6-
use rustc_hir::{Expr, ExprKind, Mutability, QPath};
6+
use rustc_hir::{self as hir, Expr, ExprKind, Mutability, QPath};
77
use rustc_lint::LateContext;
88
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
99

@@ -19,10 +19,7 @@ pub(super) fn check<'tcx>(
1919
) {
2020
if let ty::RawPtr(from_ty, from_mutbl) = cast_from.kind()
2121
&& let ty::RawPtr(to_ty, to_mutbl) = cast_to.kind()
22-
&& matches!(
23-
(from_mutbl, to_mutbl),
24-
(Mutability::Not, Mutability::Mut) | (Mutability::Mut, Mutability::Not)
25-
)
22+
&& from_mutbl != to_mutbl
2623
&& from_ty == to_ty
2724
&& !from_ty.has_erased_regions()
2825
{

0 commit comments

Comments
 (0)