@@ -4,6 +4,7 @@ mod cast_possible_wrap;
4
4
mod cast_precision_loss;
5
5
mod cast_sign_loss;
6
6
mod fn_to_numeric_cast;
7
+ mod fn_to_numeric_cast_with_truncation;
7
8
mod unnecessary_cast;
8
9
mod utils;
9
10
@@ -304,7 +305,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
304
305
}
305
306
306
307
fn_to_numeric_cast:: check ( cx, expr, cast_expr, cast_from, cast_to) ;
307
- lint_fn_to_numeric_cast ( cx, expr, cast_expr, cast_from, cast_to) ;
308
+ fn_to_numeric_cast_with_truncation :: check ( cx, expr, cast_expr, cast_from, cast_to) ;
308
309
lint_cast_ptr_alignment ( cx, expr, cast_from, cast_to) ;
309
310
if cast_from. is_numeric ( ) && cast_to. is_numeric ( ) && !in_external_macro ( cx. sess ( ) , expr. span ) {
310
311
cast_possible_truncation:: check ( cx, expr, cast_from, cast_to) ;
@@ -358,43 +359,6 @@ fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, cast_f
358
359
}
359
360
}
360
361
361
- fn lint_fn_to_numeric_cast (
362
- cx : & LateContext < ' _ > ,
363
- expr : & Expr < ' _ > ,
364
- cast_expr : & Expr < ' _ > ,
365
- cast_from : Ty < ' _ > ,
366
- cast_to : Ty < ' _ > ,
367
- ) {
368
- // We only want to check casts to `ty::Uint` or `ty::Int`
369
- match cast_to. kind ( ) {
370
- ty:: Uint ( _) | ty:: Int ( ..) => { /* continue on */ } ,
371
- _ => return ,
372
- }
373
- match cast_from. kind ( ) {
374
- ty:: FnDef ( ..) | ty:: FnPtr ( _) => {
375
- let mut applicability = Applicability :: MaybeIncorrect ;
376
- let from_snippet = snippet_with_applicability ( cx, cast_expr. span , "x" , & mut applicability) ;
377
-
378
- let to_nbits = int_ty_to_nbits ( cast_to, cx. tcx ) ;
379
- if to_nbits < cx. tcx . data_layout . pointer_size . bits ( ) {
380
- span_lint_and_sugg (
381
- cx,
382
- FN_TO_NUMERIC_CAST_WITH_TRUNCATION ,
383
- expr. span ,
384
- & format ! (
385
- "casting function pointer `{}` to `{}`, which truncates the value" ,
386
- from_snippet, cast_to
387
- ) ,
388
- "try" ,
389
- format ! ( "{} as usize" , from_snippet) ,
390
- applicability,
391
- ) ;
392
- }
393
- } ,
394
- _ => { } ,
395
- }
396
- }
397
-
398
362
declare_clippy_lint ! {
399
363
/// **What it does:** Checks for casts of `&T` to `&mut T` anywhere in the code.
400
364
///
0 commit comments