@@ -302,8 +302,14 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
302302 return ;
303303 }
304304 lint_fn_to_numeric_cast ( cx, expr, cast_expr, cast_from, cast_to) ;
305- lint_numeric_casts ( cx, expr, cast_expr, cast_from, cast_to) ;
306305 lint_cast_ptr_alignment ( cx, expr, cast_from, cast_to) ;
306+ if cast_from. is_numeric ( ) && cast_to. is_numeric ( ) && !in_external_macro ( cx. sess ( ) , expr. span ) {
307+ cast_possible_truncation:: check ( cx, expr, cast_from, cast_to) ;
308+ cast_possible_wrap:: check ( cx, expr, cast_from, cast_to) ;
309+ cast_precision_loss:: check ( cx, expr, cast_from, cast_to) ;
310+ cast_lossless:: check ( cx, expr, cast_expr, cast_from, cast_to) ;
311+ cast_sign_loss:: check ( cx, expr, cast_expr, cast_from, cast_to) ;
312+ }
307313 } else if let ExprKind :: MethodCall ( method_path, _, args, _) = expr. kind {
308314 if_chain ! {
309315 if method_path. ident. name == sym!( cast) ;
@@ -321,22 +327,6 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
321327 }
322328}
323329
324- fn lint_numeric_casts < ' tcx > (
325- cx : & LateContext < ' tcx > ,
326- expr : & Expr < ' tcx > ,
327- cast_op : & Expr < ' _ > ,
328- cast_from : Ty < ' tcx > ,
329- cast_to : Ty < ' tcx > ,
330- ) {
331- if cast_from. is_numeric ( ) && cast_to. is_numeric ( ) && !in_external_macro ( cx. sess ( ) , expr. span ) {
332- cast_possible_truncation:: check ( cx, expr, cast_from, cast_to) ;
333- cast_possible_wrap:: check ( cx, expr, cast_from, cast_to) ;
334- cast_precision_loss:: check ( cx, expr, cast_from, cast_to) ;
335- cast_lossless:: check ( cx, expr, cast_op, cast_from, cast_to) ;
336- cast_sign_loss:: check ( cx, expr, cast_op, cast_from, cast_to) ;
337- }
338- }
339-
340330fn lint_cast_ptr_alignment < ' tcx > ( cx : & LateContext < ' tcx > , expr : & Expr < ' _ > , cast_from : Ty < ' tcx > , cast_to : Ty < ' tcx > ) {
341331 if_chain ! {
342332 if let ty:: RawPtr ( from_ptr_ty) = & cast_from. kind( ) ;
0 commit comments