@@ -3,7 +3,7 @@ use clippy_utils::source::snippet_with_applicability;
3
3
use rustc_errors:: Applicability ;
4
4
use rustc_hir:: Expr ;
5
5
use rustc_lint:: LateContext ;
6
- use rustc_middle:: ty:: { self , Ty } ;
6
+ use rustc_middle:: ty:: Ty ;
7
7
8
8
use super :: { FN_TO_NUMERIC_CAST_WITH_TRUNCATION , utils} ;
9
9
@@ -12,23 +12,20 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
12
12
let Some ( to_nbits) = utils:: int_ty_to_nbits ( cx. tcx , cast_to) else {
13
13
return ;
14
14
} ;
15
- match cast_from. kind ( ) {
16
- ty:: FnDef ( ..) | ty:: FnPtr ( ..) => {
17
- let mut applicability = Applicability :: MaybeIncorrect ;
18
- let from_snippet = snippet_with_applicability ( cx, cast_expr. span , "x" , & mut applicability) ;
15
+ if cast_from. is_fn ( ) {
16
+ let mut applicability = Applicability :: MaybeIncorrect ;
17
+ let from_snippet = snippet_with_applicability ( cx, cast_expr. span , "x" , & mut applicability) ;
19
18
20
- if to_nbits < cx. tcx . data_layout . pointer_size ( ) . bits ( ) {
21
- span_lint_and_sugg (
22
- cx,
23
- FN_TO_NUMERIC_CAST_WITH_TRUNCATION ,
24
- expr. span ,
25
- format ! ( "casting function pointer `{from_snippet}` to `{cast_to}`, which truncates the value" ) ,
26
- "try" ,
27
- format ! ( "{from_snippet} as usize" ) ,
28
- applicability,
29
- ) ;
30
- }
31
- } ,
32
- _ => { } ,
19
+ if to_nbits < cx. tcx . data_layout . pointer_size ( ) . bits ( ) {
20
+ span_lint_and_sugg (
21
+ cx,
22
+ FN_TO_NUMERIC_CAST_WITH_TRUNCATION ,
23
+ expr. span ,
24
+ format ! ( "casting function pointer `{from_snippet}` to `{cast_to}`, which truncates the value" ) ,
25
+ "try" ,
26
+ format ! ( "{from_snippet} as usize" ) ,
27
+ applicability,
28
+ ) ;
29
+ }
33
30
}
34
31
}
0 commit comments