@@ -48,23 +48,22 @@ declare_lint_pass!(NonZeroSuggestions => [NON_ZERO_SUGGESTIONS]);
4848
4949impl < ' tcx > LateLintPass < ' tcx > for NonZeroSuggestions {
5050 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > ) {
51- if let ExprKind :: Call ( func, [ arg] ) = expr. kind {
52- if let ExprKind :: Path ( qpath) = & func. kind {
53- if let Some ( def_id) = cx. qpath_res ( qpath, func. hir_id ) . opt_def_id ( ) {
54- let fn_name = cx. tcx . item_name ( def_id) ;
55- let target_ty = cx. typeck_results ( ) . expr_ty ( expr) ;
51+ if let ExprKind :: Call ( func, [ arg] ) = expr. kind
52+ && let ExprKind :: Path ( qpath) = & func. kind
53+ && let Some ( def_id) = cx. qpath_res ( qpath, func. hir_id ) . opt_def_id ( )
54+ && let ExprKind :: MethodCall ( rcv_path, receiver, _, _) = & arg. kind
55+ {
56+ let fn_name = cx. tcx . item_name ( def_id) ;
57+ let target_ty = cx. typeck_results ( ) . expr_ty ( expr) ;
58+ let receiver_ty = cx. typeck_results ( ) . expr_ty ( receiver) ;
5659
57- if let ExprKind :: MethodCall ( rcv_path, receiver, _, _) = & arg. kind {
58- let receiver_ty = cx. typeck_results ( ) . expr_ty ( receiver) ;
59- if let ty:: Adt ( adt_def, _) = receiver_ty. kind ( ) {
60- if adt_def. is_struct ( ) && cx. tcx . get_diagnostic_name ( adt_def. did ( ) ) == Some ( sym:: NonZero ) {
61- if let Some ( target_non_zero_type) = get_target_non_zero_type ( target_ty) {
62- let arg_snippet = get_arg_snippet ( cx, arg, rcv_path) ;
63- suggest_non_zero_conversion ( cx, expr, fn_name, target_non_zero_type, & arg_snippet) ;
64- }
65- }
66- }
67- }
60+ if let ty:: Adt ( adt_def, _) = receiver_ty. kind ( )
61+ && adt_def. is_struct ( )
62+ && cx. tcx . get_diagnostic_name ( adt_def. did ( ) ) == Some ( sym:: NonZero )
63+ {
64+ if let Some ( target_non_zero_type) = get_target_non_zero_type ( target_ty) {
65+ let arg_snippet = get_arg_snippet ( cx, arg, rcv_path) ;
66+ suggest_non_zero_conversion ( cx, expr, fn_name, target_non_zero_type, & arg_snippet) ;
6867 }
6968 }
7069 }
0 commit comments