@@ -100,8 +100,9 @@ impl<'tcx> TraitDef {
100
100
}
101
101
102
102
impl < ' tcx > TyCtxt < ' tcx > {
103
- pub fn for_each_impl < F : FnMut ( DefId ) > ( self , def_id : DefId , mut f : F ) {
104
- let impls = self . trait_impls_of ( def_id) ;
103
+ /// `trait_def_id` MUST BE the `DefId` of a trait.
104
+ pub fn for_each_impl < F : FnMut ( DefId ) > ( self , trait_def_id : DefId , mut f : F ) {
105
+ let impls = self . trait_impls_of ( trait_def_id) ;
105
106
106
107
for & impl_def_id in impls. blanket_impls . iter ( ) {
107
108
f ( impl_def_id) ;
@@ -114,26 +115,28 @@ impl<'tcx> TyCtxt<'tcx> {
114
115
}
115
116
}
116
117
117
- /// Iterate over every impl that could possibly match the
118
- /// self type `self_ty`.
118
+ /// Iterate over every impl that could possibly match the self type `self_ty`.
119
+ ///
120
+ /// `trait_def_id` MUST BE the `DefId` of a trait.
119
121
pub fn for_each_relevant_impl < F : FnMut ( DefId ) > (
120
122
self ,
121
- def_id : DefId ,
123
+ trait_def_id : DefId ,
122
124
self_ty : Ty < ' tcx > ,
123
125
mut f : F ,
124
126
) {
125
- let _: Option < ( ) > = self . find_map_relevant_impl ( def_id , self_ty, |did| {
127
+ let _: Option < ( ) > = self . find_map_relevant_impl ( trait_def_id , self_ty, |did| {
126
128
f ( did) ;
127
129
None
128
130
} ) ;
129
131
}
130
132
133
+ /// `trait_def_id` MUST BE the `DefId` of a trait.
131
134
pub fn non_blanket_impls_for_ty (
132
135
self ,
133
- def_id : DefId ,
136
+ trait_def_id : DefId ,
134
137
self_ty : Ty < ' tcx > ,
135
138
) -> impl Iterator < Item = DefId > + ' tcx {
136
- let impls = self . trait_impls_of ( def_id ) ;
139
+ let impls = self . trait_impls_of ( trait_def_id ) ;
137
140
if let Some ( simp) = fast_reject:: simplify_type ( self , self_ty, TreatParams :: AsInfer ) {
138
141
if let Some ( impls) = impls. non_blanket_impls . get ( & simp) {
139
142
return impls. iter ( ) . copied ( ) ;
@@ -145,9 +148,11 @@ impl<'tcx> TyCtxt<'tcx> {
145
148
146
149
/// Applies function to every impl that could possibly match the self type `self_ty` and returns
147
150
/// the first non-none value.
151
+ ///
152
+ /// `trait_def_id` MUST BE the `DefId` of a trait.
148
153
pub fn find_map_relevant_impl < T , F : FnMut ( DefId ) -> Option < T > > (
149
154
self ,
150
- def_id : DefId ,
155
+ trait_def_id : DefId ,
151
156
self_ty : Ty < ' tcx > ,
152
157
mut f : F ,
153
158
) -> Option < T > {
@@ -156,7 +161,7 @@ impl<'tcx> TyCtxt<'tcx> {
156
161
//
157
162
// If we want to be faster, we could have separate queries for
158
163
// blanket and non-blanket impls, and compare them separately.
159
- let impls = self . trait_impls_of ( def_id ) ;
164
+ let impls = self . trait_impls_of ( trait_def_id ) ;
160
165
161
166
for & impl_def_id in impls. blanket_impls . iter ( ) {
162
167
if let result @ Some ( _) = f ( impl_def_id) {
@@ -190,9 +195,11 @@ impl<'tcx> TyCtxt<'tcx> {
190
195
None
191
196
}
192
197
193
- /// Returns an iterator containing all impls
194
- pub fn all_impls ( self , def_id : DefId ) -> impl Iterator < Item = DefId > + ' tcx {
195
- let TraitImpls { blanket_impls, non_blanket_impls } = self . trait_impls_of ( def_id) ;
198
+ /// Returns an iterator containing all impls for `trait_def_id`.
199
+ ///
200
+ /// `trait_def_id` MUST BE the `DefId` of a trait.
201
+ pub fn all_impls ( self , trait_def_id : DefId ) -> impl Iterator < Item = DefId > + ' tcx {
202
+ let TraitImpls { blanket_impls, non_blanket_impls } = self . trait_impls_of ( trait_def_id) ;
196
203
197
204
blanket_impls. iter ( ) . chain ( non_blanket_impls. iter ( ) . flat_map ( |( _, v) | v) ) . cloned ( )
198
205
}
0 commit comments