@@ -1224,13 +1224,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12241224 {
12251225 self . note_obligation_cause_code ( err,
12261226 & obligation. predicate ,
1227- & obligation. cause . code ) ;
1227+ & obligation. cause . code ,
1228+ & mut vec ! [ ] ) ;
12281229 }
12291230
12301231 fn note_obligation_cause_code < T > ( & self ,
12311232 err : & mut DiagnosticBuilder ,
12321233 predicate : & T ,
1233- cause_code : & ObligationCauseCode < ' tcx > )
1234+ cause_code : & ObligationCauseCode < ' tcx > ,
1235+ obligated_types : & mut Vec < & ty:: TyS < ' tcx > > )
12341236 where T : fmt:: Display
12351237 {
12361238 let tcx = self . tcx ;
@@ -1326,12 +1328,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13261328 }
13271329 ObligationCauseCode :: BuiltinDerivedObligation ( ref data) => {
13281330 let parent_trait_ref = self . resolve_type_vars_if_possible ( & data. parent_trait_ref ) ;
1329- err. note ( & format ! ( "required because it appears within the type `{}`" ,
1330- parent_trait_ref. 0 . self_ty( ) ) ) ;
1331+ let ty = parent_trait_ref. 0 . self_ty ( ) ;
1332+ err. note ( & format ! ( "required because it appears within the type `{}`" , ty) ) ;
1333+ obligated_types. push ( ty) ;
1334+
13311335 let parent_predicate = parent_trait_ref. to_predicate ( ) ;
1332- self . note_obligation_cause_code ( err,
1333- & parent_predicate,
1334- & data. parent_code ) ;
1336+ if !self . is_recursive_obligation ( obligated_types, & data. parent_code ) {
1337+ self . note_obligation_cause_code ( err,
1338+ & parent_predicate,
1339+ & data. parent_code ,
1340+ obligated_types) ;
1341+ }
13351342 }
13361343 ObligationCauseCode :: ImplDerivedObligation ( ref data) => {
13371344 let parent_trait_ref = self . resolve_type_vars_if_possible ( & data. parent_trait_ref ) ;
@@ -1341,8 +1348,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13411348 parent_trait_ref. 0 . self_ty( ) ) ) ;
13421349 let parent_predicate = parent_trait_ref. to_predicate ( ) ;
13431350 self . note_obligation_cause_code ( err,
1344- & parent_predicate,
1345- & data. parent_code ) ;
1351+ & parent_predicate,
1352+ & data. parent_code ,
1353+ obligated_types) ;
13461354 }
13471355 ObligationCauseCode :: CompareImplMethodObligation { .. } => {
13481356 err. note (
@@ -1361,6 +1369,20 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13611369 err. help ( & format ! ( "consider adding a `#![recursion_limit=\" {}\" ]` attribute to your crate" ,
13621370 suggested_limit) ) ;
13631371 }
1372+
1373+ fn is_recursive_obligation ( & self ,
1374+ obligated_types : & mut Vec < & ty:: TyS < ' tcx > > ,
1375+ cause_code : & ObligationCauseCode < ' tcx > ) -> bool {
1376+ if let ObligationCauseCode :: BuiltinDerivedObligation ( ref data) = cause_code {
1377+ let parent_trait_ref = self . resolve_type_vars_if_possible ( & data. parent_trait_ref ) ;
1378+ for obligated_type in obligated_types {
1379+ if obligated_type == & parent_trait_ref. 0 . self_ty ( ) {
1380+ return true ;
1381+ }
1382+ }
1383+ }
1384+ return false ;
1385+ }
13641386}
13651387
13661388enum ArgKind {
0 commit comments