@@ -100,8 +100,9 @@ impl<'tcx> TraitDef {
100100}
101101
102102impl < ' 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) ;
105106
106107 for & impl_def_id in impls. blanket_impls . iter ( ) {
107108 f ( impl_def_id) ;
@@ -114,26 +115,28 @@ impl<'tcx> TyCtxt<'tcx> {
114115 }
115116 }
116117
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.
119121 pub fn for_each_relevant_impl < F : FnMut ( DefId ) > (
120122 self ,
121- def_id : DefId ,
123+ trait_def_id : DefId ,
122124 self_ty : Ty < ' tcx > ,
123125 mut f : F ,
124126 ) {
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| {
126128 f ( did) ;
127129 None
128130 } ) ;
129131 }
130132
133+ /// `trait_def_id` MUST BE the `DefId` of a trait.
131134 pub fn non_blanket_impls_for_ty (
132135 self ,
133- def_id : DefId ,
136+ trait_def_id : DefId ,
134137 self_ty : Ty < ' tcx > ,
135138 ) -> impl Iterator < Item = DefId > + ' tcx {
136- let impls = self . trait_impls_of ( def_id ) ;
139+ let impls = self . trait_impls_of ( trait_def_id ) ;
137140 if let Some ( simp) = fast_reject:: simplify_type ( self , self_ty, TreatParams :: AsInfer ) {
138141 if let Some ( impls) = impls. non_blanket_impls . get ( & simp) {
139142 return impls. iter ( ) . copied ( ) ;
@@ -145,9 +148,11 @@ impl<'tcx> TyCtxt<'tcx> {
145148
146149 /// Applies function to every impl that could possibly match the self type `self_ty` and returns
147150 /// the first non-none value.
151+ ///
152+ /// `trait_def_id` MUST BE the `DefId` of a trait.
148153 pub fn find_map_relevant_impl < T , F : FnMut ( DefId ) -> Option < T > > (
149154 self ,
150- def_id : DefId ,
155+ trait_def_id : DefId ,
151156 self_ty : Ty < ' tcx > ,
152157 mut f : F ,
153158 ) -> Option < T > {
@@ -156,7 +161,7 @@ impl<'tcx> TyCtxt<'tcx> {
156161 //
157162 // If we want to be faster, we could have separate queries for
158163 // 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 ) ;
160165
161166 for & impl_def_id in impls. blanket_impls . iter ( ) {
162167 if let result @ Some ( _) = f ( impl_def_id) {
@@ -190,9 +195,11 @@ impl<'tcx> TyCtxt<'tcx> {
190195 None
191196 }
192197
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) ;
196203
197204 blanket_impls. iter ( ) . chain ( non_blanket_impls. iter ( ) . flat_map ( |( _, v) | v) ) . cloned ( )
198205 }
0 commit comments