@@ -657,7 +657,7 @@ fn lint_nan<'tcx>(
657
657
fn lint_wide_pointer < ' tcx > (
658
658
cx : & LateContext < ' tcx > ,
659
659
e : & ' tcx hir:: Expr < ' tcx > ,
660
- binop : hir:: BinOpKind ,
660
+ binop : Option < hir:: BinOpKind > ,
661
661
l : & ' tcx hir:: Expr < ' tcx > ,
662
662
r : & ' tcx hir:: Expr < ' tcx > ,
663
663
) {
@@ -676,7 +676,7 @@ fn lint_wide_pointer<'tcx>(
676
676
}
677
677
} ;
678
678
679
- // PartialEq::{eq,ne} takes references, remove any explicit references
679
+ // the left and right operands can have references, remove any explicit references
680
680
let l = l. peel_borrows ( ) ;
681
681
let r = r. peel_borrows ( ) ;
682
682
@@ -704,8 +704,8 @@ fn lint_wide_pointer<'tcx>(
704
704
) ;
705
705
} ;
706
706
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 ) ) ;
709
709
let is_dyn_comparison = l_inner_ty_is_dyn && r_inner_ty_is_dyn;
710
710
711
711
let left = e. span . shrink_to_lo ( ) . until ( l_span. shrink_to_lo ( ) ) ;
@@ -742,12 +742,12 @@ fn lint_wide_pointer<'tcx>(
742
742
AmbiguousWidePointerComparisonsAddrSuggestion :: Cast {
743
743
deref_left,
744
744
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 ( ) ,
751
751
}
752
752
} ,
753
753
} ,
@@ -770,7 +770,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
770
770
cx. emit_span_lint ( UNUSED_COMPARISONS , e. span , UnusedComparisons ) ;
771
771
} else {
772
772
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) ;
774
774
}
775
775
}
776
776
}
@@ -779,14 +779,14 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
779
779
if let ExprKind :: Path ( ref qpath) = path. kind
780
780
&& let Some ( def_id) = cx. qpath_res ( qpath, path. hir_id ) . opt_def_id ( )
781
781
&& 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) =>
783
783
{
784
784
lint_wide_pointer ( cx, e, binop, l, r) ;
785
785
}
786
786
hir:: ExprKind :: MethodCall ( _, l, [ r] , _)
787
787
if let Some ( def_id) = cx. typeck_results ( ) . type_dependent_def_id ( e. hir_id )
788
788
&& 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) =>
790
790
{
791
791
lint_wide_pointer ( cx, e, binop, l, r) ;
792
792
}
@@ -873,13 +873,19 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
873
873
)
874
874
}
875
875
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 ,
883
889
}
884
890
}
885
891
}
0 commit comments