Skip to content

Commit 042556c

Browse files
Rename lint into confusing_method_to_numeric_cast
1 parent d93fba7 commit 042556c

8 files changed

+37
-28
lines changed

clippy_lints/src/casts/primitive_method_to_numeric_cast.rs renamed to clippy_lints/src/casts/confusing_method_to_numeric_cast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_hir::Expr;
66
use rustc_lint::LateContext;
77
use rustc_middle::ty::{self, Ty};
88

9-
use super::PRIMITIVE_METHOD_TO_NUMERIC_CAST;
9+
use super::CONFUSING_METHOD_TO_NUMERIC_CAST;
1010

1111
fn get_primitive_ty_name(ty: Ty<'_>) -> Option<&'static str> {
1212
match ty.kind() {
@@ -41,7 +41,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
4141

4242
span_lint_and_then(
4343
cx,
44-
PRIMITIVE_METHOD_TO_NUMERIC_CAST,
44+
CONFUSING_METHOD_TO_NUMERIC_CAST,
4545
expr.span,
4646
format!("casting function pointer `{from_snippet}` to `{cast_to}`"),
4747
|diag| {

clippy_lints/src/casts/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ mod cast_sign_loss;
1414
mod cast_slice_different_sizes;
1515
mod cast_slice_from_raw_parts;
1616
mod char_lit_as_u8;
17+
mod confusing_method_to_numeric_cast;
1718
mod fn_to_numeric_cast;
1819
mod fn_to_numeric_cast_any;
1920
mod fn_to_numeric_cast_with_truncation;
20-
mod primitive_method_to_numeric_cast;
2121
mod ptr_as_ptr;
2222
mod ptr_cast_constness;
2323
mod ref_as_ptr;
@@ -776,7 +776,7 @@ declare_clippy_lint! {
776776
/// let _ = u16::MAX as usize;
777777
/// ```
778778
#[clippy::version = "1.86.0"]
779-
pub PRIMITIVE_METHOD_TO_NUMERIC_CAST,
779+
pub CONFUSING_METHOD_TO_NUMERIC_CAST,
780780
suspicious,
781781
"casting a primitive method pointer to any integer type"
782782
}
@@ -819,7 +819,7 @@ impl_lint_pass!(Casts => [
819819
ZERO_PTR,
820820
REF_AS_PTR,
821821
AS_POINTER_UNDERSCORE,
822-
PRIMITIVE_METHOD_TO_NUMERIC_CAST,
822+
CONFUSING_METHOD_TO_NUMERIC_CAST,
823823
]);
824824

825825
impl<'tcx> LateLintPass<'tcx> for Casts {
@@ -844,7 +844,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
844844
ptr_cast_constness::check(cx, expr, cast_from_expr, cast_from, cast_to, &self.msrv);
845845
as_ptr_cast_mut::check(cx, expr, cast_from_expr, cast_to);
846846
fn_to_numeric_cast_any::check(cx, expr, cast_from_expr, cast_from, cast_to);
847-
primitive_method_to_numeric_cast::check(cx, expr, cast_from_expr, cast_from, cast_to);
847+
confusing_method_to_numeric_cast::check(cx, expr, cast_from_expr, cast_from, cast_to);
848848
fn_to_numeric_cast::check(cx, expr, cast_from_expr, cast_from, cast_to);
849849
fn_to_numeric_cast_with_truncation::check(cx, expr, cast_from_expr, cast_from, cast_to);
850850
zero_ptr::check(cx, expr, cast_from_expr, cast_to_hir);

clippy_lints/src/declared_lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub static LINTS: &[&crate::LintInfo] = &[
9696
crate::casts::FN_TO_NUMERIC_CAST_INFO,
9797
crate::casts::FN_TO_NUMERIC_CAST_ANY_INFO,
9898
crate::casts::FN_TO_NUMERIC_CAST_WITH_TRUNCATION_INFO,
99-
crate::casts::PRIMITIVE_METHOD_TO_NUMERIC_CAST_INFO,
99+
crate::casts::CONFUSING_METHOD_TO_NUMERIC_CAST_INFO,
100100
crate::casts::PTR_AS_PTR_INFO,
101101
crate::casts::PTR_CAST_CONSTNESS_INFO,
102102
crate::casts::REF_AS_PTR_INFO,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![warn(clippy::confusing_method_to_numeric_cast)]
2+
3+
fn main() {
4+
let _ = u16::MAX as usize; //~ confusing_method_to_numeric_cast
5+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::primitive_method_to_numeric_cast)]
22

33
fn main() {
4-
let _ = u16::MAX as usize; //~ primitive_method_to_numeric_cast
4+
let _ = u16::max as usize; //~ confusing_method_to_numeric_cast
55
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error: unknown lint: `clippy::primitive_method_to_numeric_cast`
2+
--> tests/ui/confusing_method_to_numeric_cast.rs:1:9
3+
|
4+
LL | #![warn(clippy::primitive_method_to_numeric_cast)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::confusing_method_to_numeric_cast`
6+
|
7+
= note: `-D unknown-lints` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(unknown_lints)]`
9+
10+
error: casting function pointer `u16::max` to `usize`
11+
--> tests/ui/confusing_method_to_numeric_cast.rs:4:13
12+
|
13+
LL | let _ = u16::max as usize;
14+
| ^^^^^^^^^^^^^^^^^
15+
|
16+
= note: `-D clippy::confusing-method-to-numeric-cast` implied by `-D warnings`
17+
= help: to override `-D warnings` add `#[allow(clippy::confusing_method_to_numeric_cast)]`
18+
help: did you mean to use the associated constant?
19+
|
20+
LL | let _ = u16::MAX as usize;
21+
| ~~~~~~~~~~~~~~~~~
22+
23+
error: aborting due to 2 previous errors
24+

tests/ui/primitive_method_to_numeric_cast.rs

-5
This file was deleted.

tests/ui/primitive_method_to_numeric_cast.stderr

-15
This file was deleted.

0 commit comments

Comments
 (0)