@@ -2055,13 +2055,37 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
2055
2055
}
2056
2056
}
2057
2057
ObligationCauseCode :: ImplDerivedObligation ( ref data) => {
2058
- let parent_trait_ref = self . resolve_vars_if_possible ( data. parent_trait_ref ) ;
2058
+ let mut parent_trait_ref = self . resolve_vars_if_possible ( data. parent_trait_ref ) ;
2059
2059
err. note ( & format ! (
2060
2060
"required because of the requirements on the impl of `{}` for `{}`" ,
2061
2061
parent_trait_ref. print_only_trait_path( ) ,
2062
2062
parent_trait_ref. skip_binder( ) . self_ty( )
2063
2063
) ) ;
2064
- let parent_predicate = parent_trait_ref. without_const ( ) . to_predicate ( tcx) ;
2064
+
2065
+ let mut parent_predicate = parent_trait_ref. without_const ( ) . to_predicate ( tcx) ;
2066
+ let mut data = data;
2067
+ let mut redundant = false ;
2068
+ let mut count = 0 ;
2069
+ while let ObligationCauseCode :: ImplDerivedObligation ( child) = & * data. parent_code {
2070
+ // Skip redundant recursive obligation notes. See `ui/issue-20413.rs`.
2071
+ 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 ( ) {
2073
+ break ;
2074
+ }
2075
+ count += 1 ;
2076
+ redundant = true ;
2077
+ data = child;
2078
+ parent_predicate = child_trait_ref. without_const ( ) . to_predicate ( tcx) ;
2079
+ parent_trait_ref = child_trait_ref;
2080
+ }
2081
+ if redundant {
2082
+ err. note ( & format ! ( "{} redundant requirements hidden" , count) ) ;
2083
+ err. note ( & format ! (
2084
+ "required because of the requirements on the impl of `{}` for `{}`" ,
2085
+ parent_trait_ref. print_only_trait_path( ) ,
2086
+ parent_trait_ref. skip_binder( ) . self_ty( )
2087
+ ) ) ;
2088
+ }
2065
2089
// #74711: avoid a stack overflow
2066
2090
ensure_sufficient_stack ( || {
2067
2091
self . note_obligation_cause_code (
@@ -2087,15 +2111,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
2087
2111
}
2088
2112
ObligationCauseCode :: CompareImplMethodObligation { .. } => {
2089
2113
err. note ( & format ! (
2090
- "the requirement `{}` appears on the impl method \
2091
- but not on the corresponding trait method",
2114
+ "the requirement `{}` appears on the impl method but not on the corresponding \
2115
+ trait method",
2092
2116
predicate
2093
2117
) ) ;
2094
2118
}
2095
2119
ObligationCauseCode :: CompareImplTypeObligation { .. } => {
2096
2120
err. note ( & format ! (
2097
- "the requirement `{}` appears on the associated impl type \
2098
- but not on the corresponding associated trait type",
2121
+ "the requirement `{}` appears on the associated impl type but not on the \
2122
+ corresponding associated trait type",
2099
2123
predicate
2100
2124
) ) ;
2101
2125
}
0 commit comments