@@ -7,6 +7,7 @@ use crate::autoderef::Autoderef;
77use crate :: infer:: InferCtxt ;
88use crate :: traits:: normalize_projection_type;
99
10+ use rustc_data_structures:: fx:: FxHashSet ;
1011use rustc_data_structures:: stack:: ensure_sufficient_stack;
1112use rustc_errors:: { error_code, struct_span_err, Applicability , DiagnosticBuilder , Style } ;
1213use rustc_hir as hir;
@@ -158,6 +159,7 @@ pub trait InferCtxtExt<'tcx> {
158159 predicate : & T ,
159160 cause_code : & ObligationCauseCode < ' tcx > ,
160161 obligated_types : & mut Vec < & ty:: TyS < ' tcx > > ,
162+ seen_requirements : & mut FxHashSet < DefId > ,
161163 ) where
162164 T : fmt:: Display ;
163165
@@ -1787,6 +1789,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
17871789 & obligation. predicate ,
17881790 next_code. unwrap ( ) ,
17891791 & mut Vec :: new ( ) ,
1792+ & mut Default :: default ( ) ,
17901793 ) ;
17911794 }
17921795
@@ -1796,6 +1799,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
17961799 predicate : & T ,
17971800 cause_code : & ObligationCauseCode < ' tcx > ,
17981801 obligated_types : & mut Vec < & ty:: TyS < ' tcx > > ,
1802+ seen_requirements : & mut FxHashSet < DefId > ,
17991803 ) where
18001804 T : fmt:: Display ,
18011805 {
@@ -2050,12 +2054,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
20502054 & parent_predicate,
20512055 & data. parent_code ,
20522056 obligated_types,
2057+ seen_requirements,
20532058 )
20542059 } ) ;
20552060 }
20562061 }
20572062 ObligationCauseCode :: ImplDerivedObligation ( ref data) => {
20582063 let mut parent_trait_ref = self . resolve_vars_if_possible ( data. parent_trait_ref ) ;
2064+ let parent_def_id = parent_trait_ref. def_id ( ) ;
20592065 err. note ( & format ! (
20602066 "required because of the requirements on the impl of `{}` for `{}`" ,
20612067 parent_trait_ref. print_only_trait_path( ) ,
@@ -2066,10 +2072,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
20662072 let mut data = data;
20672073 let mut redundant = false ;
20682074 let mut count = 0 ;
2075+ seen_requirements. insert ( parent_def_id) ;
20692076 while let ObligationCauseCode :: ImplDerivedObligation ( child) = & * data. parent_code {
20702077 // Skip redundant recursive obligation notes. See `ui/issue-20413.rs`.
20712078 let child_trait_ref = self . resolve_vars_if_possible ( child. parent_trait_ref ) ;
2072- if parent_trait_ref. def_id ( ) != child_trait_ref. def_id ( ) {
2079+ let child_def_id = child_trait_ref. def_id ( ) ;
2080+ if seen_requirements. insert ( child_def_id) {
20732081 break ;
20742082 }
20752083 count += 1 ;
@@ -2093,6 +2101,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
20932101 & parent_predicate,
20942102 & data. parent_code ,
20952103 obligated_types,
2104+ seen_requirements,
20962105 )
20972106 } ) ;
20982107 }
@@ -2106,6 +2115,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
21062115 & parent_predicate,
21072116 & data. parent_code ,
21082117 obligated_types,
2118+ seen_requirements,
21092119 )
21102120 } ) ;
21112121 }
0 commit comments