Skip to content

Commit

Permalink
Rename lint into confusing_method_to_numeric_cast
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jan 10, 2025
1 parent d93fba7 commit 042556c
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_hir::Expr;
use rustc_lint::LateContext;
use rustc_middle::ty::{self, Ty};

use super::PRIMITIVE_METHOD_TO_NUMERIC_CAST;
use super::CONFUSING_METHOD_TO_NUMERIC_CAST;

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

span_lint_and_then(
cx,
PRIMITIVE_METHOD_TO_NUMERIC_CAST,
CONFUSING_METHOD_TO_NUMERIC_CAST,
expr.span,
format!("casting function pointer `{from_snippet}` to `{cast_to}`"),
|diag| {
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/casts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ mod cast_sign_loss;
mod cast_slice_different_sizes;
mod cast_slice_from_raw_parts;
mod char_lit_as_u8;
mod confusing_method_to_numeric_cast;
mod fn_to_numeric_cast;
mod fn_to_numeric_cast_any;
mod fn_to_numeric_cast_with_truncation;
mod primitive_method_to_numeric_cast;
mod ptr_as_ptr;
mod ptr_cast_constness;
mod ref_as_ptr;
Expand Down Expand Up @@ -776,7 +776,7 @@ declare_clippy_lint! {
/// let _ = u16::MAX as usize;
/// ```
#[clippy::version = "1.86.0"]
pub PRIMITIVE_METHOD_TO_NUMERIC_CAST,
pub CONFUSING_METHOD_TO_NUMERIC_CAST,
suspicious,
"casting a primitive method pointer to any integer type"
}
Expand Down Expand Up @@ -819,7 +819,7 @@ impl_lint_pass!(Casts => [
ZERO_PTR,
REF_AS_PTR,
AS_POINTER_UNDERSCORE,
PRIMITIVE_METHOD_TO_NUMERIC_CAST,
CONFUSING_METHOD_TO_NUMERIC_CAST,
]);

impl<'tcx> LateLintPass<'tcx> for Casts {
Expand All @@ -844,7 +844,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
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);
primitive_method_to_numeric_cast::check(cx, expr, cast_from_expr, cast_from, cast_to);
confusing_method_to_numeric_cast::check(cx, expr, cast_from_expr, cast_from, cast_to);
fn_to_numeric_cast::check(cx, expr, cast_from_expr, cast_from, cast_to);
fn_to_numeric_cast_with_truncation::check(cx, expr, cast_from_expr, cast_from, cast_to);
zero_ptr::check(cx, expr, cast_from_expr, cast_to_hir);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/declared_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub static LINTS: &[&crate::LintInfo] = &[
crate::casts::FN_TO_NUMERIC_CAST_INFO,
crate::casts::FN_TO_NUMERIC_CAST_ANY_INFO,
crate::casts::FN_TO_NUMERIC_CAST_WITH_TRUNCATION_INFO,
crate::casts::PRIMITIVE_METHOD_TO_NUMERIC_CAST_INFO,
crate::casts::CONFUSING_METHOD_TO_NUMERIC_CAST_INFO,
crate::casts::PTR_AS_PTR_INFO,
crate::casts::PTR_CAST_CONSTNESS_INFO,
crate::casts::REF_AS_PTR_INFO,
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/confusing_method_to_numeric_cast.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![warn(clippy::confusing_method_to_numeric_cast)]

fn main() {
let _ = u16::MAX as usize; //~ confusing_method_to_numeric_cast
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![warn(clippy::primitive_method_to_numeric_cast)]

fn main() {
let _ = u16::MAX as usize; //~ primitive_method_to_numeric_cast
let _ = u16::max as usize; //~ confusing_method_to_numeric_cast
}
24 changes: 24 additions & 0 deletions tests/ui/confusing_method_to_numeric_cast.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
error: unknown lint: `clippy::primitive_method_to_numeric_cast`
--> tests/ui/confusing_method_to_numeric_cast.rs:1:9
|
LL | #![warn(clippy::primitive_method_to_numeric_cast)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::confusing_method_to_numeric_cast`
|
= note: `-D unknown-lints` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(unknown_lints)]`

error: casting function pointer `u16::max` to `usize`
--> tests/ui/confusing_method_to_numeric_cast.rs:4:13
|
LL | let _ = u16::max as usize;
| ^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::confusing-method-to-numeric-cast` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::confusing_method_to_numeric_cast)]`
help: did you mean to use the associated constant?
|
LL | let _ = u16::MAX as usize;
| ~~~~~~~~~~~~~~~~~

error: aborting due to 2 previous errors

5 changes: 0 additions & 5 deletions tests/ui/primitive_method_to_numeric_cast.rs

This file was deleted.

15 changes: 0 additions & 15 deletions tests/ui/primitive_method_to_numeric_cast.stderr

This file was deleted.

0 comments on commit 042556c

Please sign in to comment.