@@ -334,11 +334,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
334
334
|db| {
335
335
let sugg = if binop. node == BinOpKind :: Or { !sugg } else { sugg } ;
336
336
db. span_suggestion_with_applicability(
337
- s. span,
337
+ s. span,
338
338
"replace it with" ,
339
339
format!(
340
340
"if {} {{ {}; }}" ,
341
- sugg,
341
+ sugg,
342
342
& snippet( cx, b. span, ".." ) ,
343
343
) ,
344
344
Applicability :: MachineApplicable , // snippet
@@ -520,16 +520,17 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr, other: &Expr) {
520
520
None => return ,
521
521
} ;
522
522
523
- // *arg impls PartialEq<other>
524
- if !arg_ty
523
+ let deref_arg_impl_partial_eq_other = arg_ty
525
524
. builtin_deref ( true )
526
- . map_or ( false , |tam| implements_trait ( cx, tam. ty , partial_eq_trait_id, & [ other_ty. into ( ) ] ) )
527
- // arg impls PartialEq<*other>
528
- && !other_ty
525
+ . map_or ( false , |tam| implements_trait ( cx, tam. ty , partial_eq_trait_id, & [ other_ty. into ( ) ] ) ) ;
526
+ let arg_impl_partial_eq_deref_other = other_ty
529
527
. builtin_deref ( true )
530
- . map_or ( false , |tam| implements_trait ( cx, arg_ty, partial_eq_trait_id, & [ tam. ty . into ( ) ] ) )
531
- // arg impls PartialEq<other>
532
- && !implements_trait ( cx, arg_ty, partial_eq_trait_id, & [ other_ty. into ( ) ] )
528
+ . map_or ( false , |tam| implements_trait ( cx, arg_ty, partial_eq_trait_id, & [ tam. ty . into ( ) ] ) ) ;
529
+ let arg_impl_partial_eq_other = implements_trait ( cx, arg_ty, partial_eq_trait_id, & [ other_ty. into ( ) ] ) ;
530
+
531
+ if !deref_arg_impl_partial_eq_other
532
+ && !arg_impl_partial_eq_deref_other
533
+ && !arg_impl_partial_eq_other
533
534
{
534
535
return ;
535
536
}
@@ -559,10 +560,11 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr, other: &Expr) {
559
560
}
560
561
}
561
562
}
563
+ let try_hint = if deref_arg_impl_partial_eq_other { format ! ( "*{}" , snip) } else { snip. to_string ( ) } ;
562
564
db. span_suggestion_with_applicability (
563
- expr. span ,
565
+ expr. span ,
564
566
"try" ,
565
- snip . to_string ( ) ,
567
+ try_hint ,
566
568
Applicability :: MachineApplicable , // snippet
567
569
) ;
568
570
} ,
0 commit comments