@@ -7,6 +7,7 @@ use crate::autoderef::Autoderef;
7
7
use crate :: infer:: InferCtxt ;
8
8
use crate :: traits:: normalize_projection_type;
9
9
10
+ use rustc_data_structures:: fx:: FxHashSet ;
10
11
use rustc_data_structures:: stack:: ensure_sufficient_stack;
11
12
use rustc_errors:: { error_code, struct_span_err, Applicability , DiagnosticBuilder , Style } ;
12
13
use rustc_hir as hir;
@@ -158,6 +159,7 @@ pub trait InferCtxtExt<'tcx> {
158
159
predicate : & T ,
159
160
cause_code : & ObligationCauseCode < ' tcx > ,
160
161
obligated_types : & mut Vec < & ty:: TyS < ' tcx > > ,
162
+ seen_requirements : & mut FxHashSet < DefId > ,
161
163
) where
162
164
T : fmt:: Display ;
163
165
@@ -1787,6 +1789,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1787
1789
& obligation. predicate ,
1788
1790
next_code. unwrap ( ) ,
1789
1791
& mut Vec :: new ( ) ,
1792
+ & mut Default :: default ( ) ,
1790
1793
) ;
1791
1794
}
1792
1795
@@ -1796,6 +1799,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1796
1799
predicate : & T ,
1797
1800
cause_code : & ObligationCauseCode < ' tcx > ,
1798
1801
obligated_types : & mut Vec < & ty:: TyS < ' tcx > > ,
1802
+ seen_requirements : & mut FxHashSet < DefId > ,
1799
1803
) where
1800
1804
T : fmt:: Display ,
1801
1805
{
@@ -2050,12 +2054,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
2050
2054
& parent_predicate,
2051
2055
& data. parent_code ,
2052
2056
obligated_types,
2057
+ seen_requirements,
2053
2058
)
2054
2059
} ) ;
2055
2060
}
2056
2061
}
2057
2062
ObligationCauseCode :: ImplDerivedObligation ( ref data) => {
2058
2063
let mut parent_trait_ref = self . resolve_vars_if_possible ( data. parent_trait_ref ) ;
2064
+ let parent_def_id = parent_trait_ref. def_id ( ) ;
2059
2065
err. note ( & format ! (
2060
2066
"required because of the requirements on the impl of `{}` for `{}`" ,
2061
2067
parent_trait_ref. print_only_trait_path( ) ,
@@ -2066,10 +2072,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
2066
2072
let mut data = data;
2067
2073
let mut redundant = false ;
2068
2074
let mut count = 0 ;
2075
+ seen_requirements. insert ( parent_def_id) ;
2069
2076
while let ObligationCauseCode :: ImplDerivedObligation ( child) = & * data. parent_code {
2070
2077
// Skip redundant recursive obligation notes. See `ui/issue-20413.rs`.
2071
2078
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) {
2073
2081
break ;
2074
2082
}
2075
2083
count += 1 ;
@@ -2093,6 +2101,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
2093
2101
& parent_predicate,
2094
2102
& data. parent_code ,
2095
2103
obligated_types,
2104
+ seen_requirements,
2096
2105
)
2097
2106
} ) ;
2098
2107
}
@@ -2106,6 +2115,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
2106
2115
& parent_predicate,
2107
2116
& data. parent_code ,
2108
2117
obligated_types,
2118
+ seen_requirements,
2109
2119
)
2110
2120
} ) ;
2111
2121
}
0 commit comments