File tree 2 files changed +20
-4
lines changed
rustc_trait_selection/src/traits/error_reporting
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> {
523
523
base_cause
524
524
}
525
525
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
+
526
541
pub fn parent ( & self ) -> Option < ( & Self , Option < ty:: PolyTraitPredicate < ' tcx > > ) > {
527
542
match self {
528
543
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> {
838
838
}
839
839
}
840
840
}
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 ( )
842
843
&& let hir:: Node :: Expr ( lhs) = self . tcx . hir ( ) . get ( * lhs_hir_id)
843
844
{
845
+ let trait_pred = predicate. unwrap_or ( trait_pred) ;
844
846
let lhs_ty = self . tcx . instantiate_bound_regions_with_erased ( trait_pred. self_ty ( ) ) ;
845
847
if let ty:: Ref ( ..) = * lhs_ty. kind ( ) {
846
- let autoderef = ( self . autoderef_steps ) ( lhs_ty) ;
848
+ let lhs_autoderef = ( self . autoderef_steps ) ( lhs_ty) ;
847
849
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) ) | {
849
851
// Remapping bound vars here
850
852
let trait_pred_and_ty =
851
853
trait_pred. map_bound ( |inner_trait_pred| ( inner_trait_pred, ty) ) ;
@@ -890,7 +892,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
890
892
}
891
893
}
892
894
}
893
-
894
895
false
895
896
}
896
897
You can’t perform that action at this time.
0 commit comments