@@ -657,7 +657,7 @@ fn lint_nan<'tcx>(
657657fn lint_wide_pointer < ' tcx > (
658658 cx : & LateContext < ' tcx > ,
659659 e : & ' tcx hir:: Expr < ' tcx > ,
660- binop : hir:: BinOpKind ,
660+ binop : Option < hir:: BinOpKind > ,
661661 l : & ' tcx hir:: Expr < ' tcx > ,
662662 r : & ' tcx hir:: Expr < ' tcx > ,
663663) {
@@ -676,7 +676,7 @@ fn lint_wide_pointer<'tcx>(
676676 }
677677 } ;
678678
679- // PartialEq::{eq,ne} takes references, remove any explicit references
679+ // the left and right operands can have references, remove any explicit references
680680 let l = l. peel_borrows ( ) ;
681681 let r = r. peel_borrows ( ) ;
682682
@@ -704,8 +704,8 @@ fn lint_wide_pointer<'tcx>(
704704 ) ;
705705 } ;
706706
707- let ne = if binop == hir:: BinOpKind :: Ne { "!" } else { "" } ;
708- let is_eq_ne = matches ! ( binop, hir:: BinOpKind :: Eq | hir:: BinOpKind :: Ne ) ;
707+ let ne = if binop == Some ( hir:: BinOpKind :: Ne ) { "!" } else { "" } ;
708+ let is_eq_ne = matches ! ( binop, Some ( hir:: BinOpKind :: Eq | hir:: BinOpKind :: Ne ) ) ;
709709 let is_dyn_comparison = l_inner_ty_is_dyn && r_inner_ty_is_dyn;
710710
711711 let left = e. span . shrink_to_lo ( ) . until ( l_span. shrink_to_lo ( ) ) ;
@@ -742,12 +742,12 @@ fn lint_wide_pointer<'tcx>(
742742 AmbiguousWidePointerComparisonsAddrSuggestion :: Cast {
743743 deref_left,
744744 deref_right,
745- // those two Options are required for correctness as having
746- // an empty span and an empty suggestion is not permitted
747- left_before : ( l_ty_refs != 0 ) . then_some ( left ) ,
748- right_before : ( r_ty_refs != 0 ) . then ( || r_span . shrink_to_lo ( ) ) ,
749- left : l_span . shrink_to_hi ( ) ,
750- right ,
745+ paren_left : ( l_ty_refs != 0 ) . then_some ( ")" ) . unwrap_or_default ( ) ,
746+ paren_right : ( r_ty_refs != 0 ) . then_some ( ")" ) . unwrap_or_default ( ) ,
747+ left_before : ( l_ty_refs != 0 ) . then_some ( l_span . shrink_to_lo ( ) ) ,
748+ left_after : l_span . shrink_to_hi ( ) ,
749+ right_before : ( r_ty_refs != 0 ) . then_some ( r_span . shrink_to_lo ( ) ) ,
750+ right_after : r_span . shrink_to_hi ( ) ,
751751 }
752752 } ,
753753 } ,
@@ -770,7 +770,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
770770 cx. emit_span_lint ( UNUSED_COMPARISONS , e. span , UnusedComparisons ) ;
771771 } else {
772772 lint_nan ( cx, e, binop, l, r) ;
773- lint_wide_pointer ( cx, e, binop. node , l, r) ;
773+ lint_wide_pointer ( cx, e, Some ( binop. node ) , l, r) ;
774774 }
775775 }
776776 }
@@ -779,14 +779,14 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
779779 if let ExprKind :: Path ( ref qpath) = path. kind
780780 && let Some ( def_id) = cx. qpath_res ( qpath, path. hir_id ) . opt_def_id ( )
781781 && let Some ( diag_item) = cx. tcx . get_diagnostic_name ( def_id)
782- && let Some ( binop) = partialeq_binop ( diag_item) =>
782+ && let Some ( binop) = diag_item_binop ( diag_item) =>
783783 {
784784 lint_wide_pointer ( cx, e, binop, l, r) ;
785785 }
786786 hir:: ExprKind :: MethodCall ( _, l, [ r] , _)
787787 if let Some ( def_id) = cx. typeck_results ( ) . type_dependent_def_id ( e. hir_id )
788788 && let Some ( diag_item) = cx. tcx . get_diagnostic_name ( def_id)
789- && let Some ( binop) = partialeq_binop ( diag_item) =>
789+ && let Some ( binop) = diag_item_binop ( diag_item) =>
790790 {
791791 lint_wide_pointer ( cx, e, binop, l, r) ;
792792 }
@@ -873,13 +873,19 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
873873 )
874874 }
875875
876- fn partialeq_binop ( diag_item : Symbol ) -> Option < hir:: BinOpKind > {
877- if diag_item == sym:: cmp_partialeq_eq {
878- Some ( hir:: BinOpKind :: Eq )
879- } else if diag_item == sym:: cmp_partialeq_ne {
880- Some ( hir:: BinOpKind :: Ne )
881- } else {
882- None
876+ fn diag_item_binop ( diag_item : Symbol ) -> Option < Option < hir:: BinOpKind > > {
877+ match diag_item {
878+ sym:: cmp_ord_max => Some ( None ) ,
879+ sym:: cmp_ord_min => Some ( None ) ,
880+ sym:: ord_cmp_method => Some ( None ) ,
881+ sym:: cmp_partialeq_eq => Some ( Some ( hir:: BinOpKind :: Eq ) ) ,
882+ sym:: cmp_partialeq_ne => Some ( Some ( hir:: BinOpKind :: Ne ) ) ,
883+ sym:: cmp_partialord_cmp => Some ( None ) ,
884+ sym:: cmp_partialord_ge => Some ( Some ( hir:: BinOpKind :: Ge ) ) ,
885+ sym:: cmp_partialord_gt => Some ( Some ( hir:: BinOpKind :: Gt ) ) ,
886+ sym:: cmp_partialord_le => Some ( Some ( hir:: BinOpKind :: Le ) ) ,
887+ sym:: cmp_partialord_lt => Some ( Some ( hir:: BinOpKind :: Lt ) ) ,
888+ _ => None ,
883889 }
884890 }
885891 }
0 commit comments