Skip to content

Commit e276af4

Browse files
Rename lint into confusing_method_to_numeric_cast
1 parent c680419 commit e276af4

11 files changed

+40
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5594,6 +5594,7 @@ Released 2018-09-13
55945594
[`collection_is_never_read`]: https://rust-lang.github.io/rust-clippy/master/index.html#collection_is_never_read
55955595
[`comparison_chain`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_chain
55965596
[`comparison_to_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_to_empty
5597+
[`confusing_method_to_numeric_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#confusing_method_to_numeric_cast
55975598
[`const_is_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_is_empty
55985599
[`const_static_lifetime`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_static_lifetime
55995600
[`copy_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#copy_iterator
@@ -6068,7 +6069,6 @@ Released 2018-09-13
60686069
[`possible_missing_comma`]: https://rust-lang.github.io/rust-clippy/master/index.html#possible_missing_comma
60696070
[`precedence`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence
60706071
[`precedence_bits`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence_bits
6071-
[`primitive_method_to_numeric_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#primitive_method_to_numeric_cast
60726072
[`print_in_format_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_in_format_impl
60736073
[`print_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_literal
60746074
[`print_stderr`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_stderr

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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ 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;
2021
mod manual_dangling_ptr;
21-
mod primitive_method_to_numeric_cast;
2222
mod ptr_as_ptr;
2323
mod ptr_cast_constness;
2424
mod ref_as_ptr;
@@ -808,7 +808,7 @@ declare_clippy_lint! {
808808
/// let _ = u16::MAX as usize;
809809
/// ```
810810
#[clippy::version = "1.86.0"]
811-
pub PRIMITIVE_METHOD_TO_NUMERIC_CAST,
811+
pub CONFUSING_METHOD_TO_NUMERIC_CAST,
812812
suspicious,
813813
"casting a primitive method pointer to any integer type"
814814
}
@@ -850,7 +850,7 @@ impl_lint_pass!(Casts => [
850850
REF_AS_PTR,
851851
AS_POINTER_UNDERSCORE,
852852
MANUAL_DANGLING_PTR,
853-
PRIMITIVE_METHOD_TO_NUMERIC_CAST,
853+
CONFUSING_METHOD_TO_NUMERIC_CAST,
854854
]);
855855

856856
impl<'tcx> LateLintPass<'tcx> for Casts {
@@ -875,7 +875,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
875875
ptr_cast_constness::check(cx, expr, cast_from_expr, cast_from, cast_to, self.msrv);
876876
as_ptr_cast_mut::check(cx, expr, cast_from_expr, cast_to);
877877
fn_to_numeric_cast_any::check(cx, expr, cast_from_expr, cast_from, cast_to);
878-
primitive_method_to_numeric_cast::check(cx, expr, cast_from_expr, cast_from, cast_to);
878+
confusing_method_to_numeric_cast::check(cx, expr, cast_from_expr, cast_from, cast_to);
879879
fn_to_numeric_cast::check(cx, expr, cast_from_expr, cast_from, cast_to);
880880
fn_to_numeric_cast_with_truncation::check(cx, expr, cast_from_expr, cast_from, cast_to);
881881
zero_ptr::check(cx, expr, cast_from_expr, cast_to_hir);

clippy_lints/src/declared_lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ pub static LINTS: &[&crate::LintInfo] = &[
6464
crate::casts::CAST_SLICE_DIFFERENT_SIZES_INFO,
6565
crate::casts::CAST_SLICE_FROM_RAW_PARTS_INFO,
6666
crate::casts::CHAR_LIT_AS_U8_INFO,
67+
crate::casts::CONFUSING_METHOD_TO_NUMERIC_CAST_INFO,
6768
crate::casts::FN_TO_NUMERIC_CAST_INFO,
6869
crate::casts::FN_TO_NUMERIC_CAST_ANY_INFO,
6970
crate::casts::FN_TO_NUMERIC_CAST_WITH_TRUNCATION_INFO,
7071
crate::casts::MANUAL_DANGLING_PTR_INFO,
71-
crate::casts::PRIMITIVE_METHOD_TO_NUMERIC_CAST_INFO,
7272
crate::casts::PTR_AS_PTR_INFO,
7373
crate::casts::PTR_CAST_CONSTNESS_INFO,
7474
crate::casts::REF_AS_PTR_INFO,

clippy_utils/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,6 +1836,12 @@ pub fn if_sequence<'tcx>(mut expr: &'tcx Expr<'tcx>) -> (Vec<&'tcx Expr<'tcx>>,
18361836
(conds, blocks)
18371837
}
18381838

1839+
pub fn match_def_path(cx: &LateContext<'_>, did: DefId, syms: &[&str]) -> bool {
1840+
// We should probably move to Symbols in Clippy as well rather than interning every time.
1841+
let path = cx.get_def_path(did);
1842+
syms.iter().map(|x| Symbol::intern(x)).eq(path.iter().copied())
1843+
}
1844+
18391845
/// Checks if the given function kind is an async function.
18401846
pub fn is_async_fn(kind: FnKind<'_>) -> bool {
18411847
match kind {
Lines changed: 5 additions & 0 deletions
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+
}
Lines changed: 5 additions & 0 deletions
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+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: casting function pointer `u16::max` to `usize`
2+
--> tests/ui/confusing_method_to_numeric_cast.rs:4:13
3+
|
4+
LL | let _ = u16::max as usize;
5+
| ^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::confusing-method-to-numeric-cast` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::confusing_method_to_numeric_cast)]`
9+
help: did you mean to use the associated constant?
10+
|
11+
LL - let _ = u16::max as usize;
12+
LL + let _ = u16::MAX as usize;
13+
|
14+
15+
error: aborting due to 1 previous error
16+

tests/ui/primitive_method_to_numeric_cast.fixed

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/ui/primitive_method_to_numeric_cast.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/ui/primitive_method_to_numeric_cast.stderr

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)