File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed
rustc_trait_selection/src/traits/error_reporting Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -523,6 +523,21 @@ impl<'tcx> ObligationCauseCode<'tcx> {
523523 base_cause
524524 }
525525
526+ /// Returns the base obligation and the base trait predicate, if any, ignoring
527+ /// derived obligations.
528+ pub fn peel_derives_with_predicate ( & self ) -> ( & Self , Option < ty:: PolyTraitPredicate < ' tcx > > ) {
529+ let mut base_cause = self ;
530+ let mut base_trait_pred = None ;
531+ while let Some ( ( parent_code, parent_pred) ) = base_cause. parent ( ) {
532+ base_cause = parent_code;
533+ if let Some ( parent_pred) = parent_pred {
534+ base_trait_pred = Some ( parent_pred) ;
535+ }
536+ }
537+
538+ ( base_cause, base_trait_pred)
539+ }
540+
526541 pub fn parent ( & self ) -> Option < ( & Self , Option < ty:: PolyTraitPredicate < ' tcx > > ) > {
527542 match self {
528543 FunctionArgumentObligation { parent_code, .. } => Some ( ( parent_code, None ) ) ,
Original file line number Diff line number Diff line change @@ -838,14 +838,16 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
838838 }
839839 }
840840 }
841- } else if let ObligationCauseCode :: BinOp { lhs_hir_id, .. } = code
841+ } else if let ( ObligationCauseCode :: BinOp { lhs_hir_id, .. } , predicate) =
842+ code. peel_derives_with_predicate ( )
842843 && let hir:: Node :: Expr ( lhs) = self . tcx . hir ( ) . get ( * lhs_hir_id)
843844 {
845+ let trait_pred = predicate. unwrap_or ( trait_pred) ;
844846 let lhs_ty = self . tcx . instantiate_bound_regions_with_erased ( trait_pred. self_ty ( ) ) ;
845847 if let ty:: Ref ( ..) = * lhs_ty. kind ( ) {
846- let autoderef = ( self . autoderef_steps ) ( lhs_ty) ;
848+ let lhs_autoderef = ( self . autoderef_steps ) ( lhs_ty) ;
847849 if let Some ( steps) =
848- autoderef . into_iter ( ) . enumerate ( ) . find_map ( |( steps, ( ty, obligations) ) | {
850+ lhs_autoderef . into_iter ( ) . enumerate ( ) . find_map ( |( steps, ( ty, obligations) ) | {
849851 // Remapping bound vars here
850852 let trait_pred_and_ty =
851853 trait_pred. map_bound ( |inner_trait_pred| ( inner_trait_pred, ty) ) ;
@@ -890,7 +892,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
890892 }
891893 }
892894 }
893-
894895 false
895896 }
896897
You can’t perform that action at this time.
0 commit comments