Skip to content

Commit 7fe200e

Browse files
committed
derive Copy/PartialEq for Prefix
1 parent b1a21ae commit 7fe200e

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

clippy_lints/src/endian_bytes.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ enum LintKind {
7676
Big,
7777
}
7878

79+
#[derive(Clone, Copy, PartialEq)]
7980
enum Prefix {
8081
From,
8182
To,
@@ -94,8 +95,8 @@ impl LintKind {
9495
}
9596
}
9697

97-
fn as_name(&self, prefix: &Prefix) -> &str {
98-
let index = usize::from(matches!(prefix, Prefix::To));
98+
fn as_name(&self, prefix: Prefix) -> &str {
99+
let index = usize::from(prefix == Prefix::To);
99100

100101
match self {
101102
LintKind::Host => HOST_NAMES[index],
@@ -116,7 +117,7 @@ impl LateLintPass<'_> for EndianBytes {
116117
if args.is_empty();
117118
let ty = cx.typeck_results().expr_ty(receiver);
118119
if ty.is_primitive_ty();
119-
if maybe_lint_endian_bytes(cx, expr, &Prefix::To, method_name.ident.name, ty);
120+
if maybe_lint_endian_bytes(cx, expr, Prefix::To, method_name.ident.name, ty);
120121
then {
121122
return;
122123
}
@@ -130,13 +131,13 @@ impl LateLintPass<'_> for EndianBytes {
130131
let ty = cx.typeck_results().expr_ty(expr);
131132
if ty.is_primitive_ty();
132133
then {
133-
maybe_lint_endian_bytes(cx, expr, &Prefix::From, *function_name, ty);
134+
maybe_lint_endian_bytes(cx, expr, Prefix::From, *function_name, ty);
134135
}
135136
}
136137
}
137138
}
138139

139-
fn maybe_lint_endian_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, prefix: &Prefix, name: Symbol, ty: Ty<'_>) -> bool {
140+
fn maybe_lint_endian_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, prefix: Prefix, name: Symbol, ty: Ty<'_>) -> bool {
140141
let ne = LintKind::Host.as_name(prefix);
141142
let le = LintKind::Little.as_name(prefix);
142143
let be = LintKind::Big.as_name(prefix);
@@ -200,13 +201,9 @@ fn maybe_lint_endian_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, prefix: &Prefi
200201
expr.span,
201202
&format!(
202203
"usage of the {}`{ty}::{}`{}",
203-
if matches!(prefix, Prefix::From) {
204-
"function "
205-
} else {
206-
""
207-
},
204+
if prefix == Prefix::From { "function " } else { "" },
208205
lint.as_name(prefix),
209-
if matches!(prefix, Prefix::To) { " method" } else { "" },
206+
if prefix == Prefix::To { " method" } else { "" },
210207
),
211208
move |diag| {
212209
if let Some(help) = help {

0 commit comments

Comments
 (0)