@@ -123,10 +123,26 @@ impl<'tcx> TyCtxt<'tcx> {
123123 self_ty : Ty < ' tcx > ,
124124 mut f : F ,
125125 ) {
126+ let _: Option < ( ) > = self . find_map_relevant_impl ( def_id, self_ty, |did| {
127+ f ( did) ;
128+ None
129+ } ) ;
130+ }
131+
132+ /// Applies function to every impl that could possibly match the self type `self_ty` and returns
133+ /// the first non-none value.
134+ pub fn find_map_relevant_impl < T , F : FnMut ( DefId ) -> Option < T > > (
135+ self ,
136+ def_id : DefId ,
137+ self_ty : Ty < ' tcx > ,
138+ mut f : F ,
139+ ) -> Option < T > {
126140 let impls = self . trait_impls_of ( def_id) ;
127141
128142 for & impl_def_id in impls. blanket_impls . iter ( ) {
129- f ( impl_def_id) ;
143+ if let result @ Some ( _) = f ( impl_def_id) {
144+ return result;
145+ }
130146 }
131147
132148 // simplify_type(.., false) basically replaces type parameters and
@@ -154,35 +170,6 @@ impl<'tcx> TyCtxt<'tcx> {
154170 // blanket and non-blanket impls, and compare them separately.
155171 //
156172 // I think we'll cross that bridge when we get to it.
157- if let Some ( simp) = fast_reject:: simplify_type ( self , self_ty, true ) {
158- if let Some ( impls) = impls. non_blanket_impls . get ( & simp) {
159- for & impl_def_id in impls {
160- f ( impl_def_id) ;
161- }
162- }
163- } else {
164- for & impl_def_id in impls. non_blanket_impls . values ( ) . flatten ( ) {
165- f ( impl_def_id) ;
166- }
167- }
168- }
169-
170- /// Applies function to every impl that could possibly match the self type `self_ty` and returns
171- /// the first non-none value.
172- pub fn find_map_relevant_impl < T , F : Fn ( DefId ) -> Option < T > > (
173- self ,
174- def_id : DefId ,
175- self_ty : Ty < ' tcx > ,
176- f : F ,
177- ) -> Option < T > {
178- let impls = self . trait_impls_of ( def_id) ;
179-
180- for & impl_def_id in impls. blanket_impls . iter ( ) {
181- if let result @ Some ( _) = f ( impl_def_id) {
182- return result;
183- }
184- }
185-
186173 if let Some ( simp) = fast_reject:: simplify_type ( self , self_ty, true ) {
187174 if let Some ( impls) = impls. non_blanket_impls . get ( & simp) {
188175 for & impl_def_id in impls {
0 commit comments