@@ -101,12 +101,14 @@ pub(super) fn type_constructor<'a, DB: HirDatabase>(
101101 ctx : & ' a TermSearchCtx < ' a , DB > ,
102102 defs : & ' a FxHashSet < ScopeDef > ,
103103 lookup : & ' a mut LookupTable ,
104+ should_continue : & ' a dyn std:: ops:: Fn ( ) -> bool ,
104105) -> impl Iterator < Item = Expr > + ' a {
105106 let db = ctx. sema . db ;
106107 let module = ctx. scope . module ( ) ;
107108 fn variant_helper (
108109 db : & dyn HirDatabase ,
109110 lookup : & mut LookupTable ,
111+ should_continue : & dyn std:: ops:: Fn ( ) -> bool ,
110112 parent_enum : Enum ,
111113 variant : Variant ,
112114 config : & TermSearchConfig ,
@@ -152,6 +154,7 @@ pub(super) fn type_constructor<'a, DB: HirDatabase>(
152154 . chain ( ( non_default_type_params_len == 0 ) . then_some ( Vec :: new ( ) ) ) ;
153155
154156 generic_params
157+ . filter ( |_| should_continue ( ) )
155158 . filter_map ( move |generics| {
156159 // Insert default type params
157160 let mut g = generics. into_iter ( ) ;
@@ -194,8 +197,14 @@ pub(super) fn type_constructor<'a, DB: HirDatabase>(
194197 defs. iter ( )
195198 . filter_map ( move |def| match def {
196199 ScopeDef :: ModuleDef ( ModuleDef :: Variant ( it) ) => {
197- let variant_exprs =
198- variant_helper ( db, lookup, it. parent_enum ( db) , * it, & ctx. config ) ;
200+ let variant_exprs = variant_helper (
201+ db,
202+ lookup,
203+ should_continue,
204+ it. parent_enum ( db) ,
205+ * it,
206+ & ctx. config ,
207+ ) ;
199208 if variant_exprs. is_empty ( ) {
200209 return None ;
201210 }
@@ -213,7 +222,9 @@ pub(super) fn type_constructor<'a, DB: HirDatabase>(
213222 let exprs: Vec < ( Type , Vec < Expr > ) > = enum_
214223 . variants ( db)
215224 . into_iter ( )
216- . flat_map ( |it| variant_helper ( db, lookup, * enum_, it, & ctx. config ) )
225+ . flat_map ( |it| {
226+ variant_helper ( db, lookup, should_continue, * enum_, it, & ctx. config )
227+ } )
217228 . collect ( ) ;
218229
219230 if exprs. is_empty ( ) {
@@ -271,6 +282,7 @@ pub(super) fn type_constructor<'a, DB: HirDatabase>(
271282 . chain ( ( non_default_type_params_len == 0 ) . then_some ( Vec :: new ( ) ) ) ;
272283
273284 let exprs = generic_params
285+ . filter ( |_| should_continue ( ) )
274286 . filter_map ( |generics| {
275287 // Insert default type params
276288 let mut g = generics. into_iter ( ) ;
@@ -349,6 +361,7 @@ pub(super) fn free_function<'a, DB: HirDatabase>(
349361 ctx : & ' a TermSearchCtx < ' a , DB > ,
350362 defs : & ' a FxHashSet < ScopeDef > ,
351363 lookup : & ' a mut LookupTable ,
364+ should_continue : & ' a dyn std:: ops:: Fn ( ) -> bool ,
352365) -> impl Iterator < Item = Expr > + ' a {
353366 let db = ctx. sema . db ;
354367 let module = ctx. scope . module ( ) ;
@@ -390,6 +403,7 @@ pub(super) fn free_function<'a, DB: HirDatabase>(
390403 . permutations ( non_default_type_params_len) ;
391404
392405 let exprs: Vec < _ > = generic_params
406+ . filter ( |_| should_continue ( ) )
393407 . filter_map ( |generics| {
394408 // Insert default type params
395409 let mut g = generics. into_iter ( ) ;
@@ -478,6 +492,7 @@ pub(super) fn impl_method<'a, DB: HirDatabase>(
478492 ctx : & ' a TermSearchCtx < ' a , DB > ,
479493 _defs : & ' a FxHashSet < ScopeDef > ,
480494 lookup : & ' a mut LookupTable ,
495+ should_continue : & ' a dyn std:: ops:: Fn ( ) -> bool ,
481496) -> impl Iterator < Item = Expr > + ' a {
482497 let db = ctx. sema . db ;
483498 let module = ctx. scope . module ( ) ;
@@ -554,6 +569,7 @@ pub(super) fn impl_method<'a, DB: HirDatabase>(
554569 . permutations ( non_default_fn_type_params_len) ;
555570
556571 let exprs: Vec < _ > = generic_params
572+ . filter ( |_| should_continue ( ) )
557573 . filter_map ( |generics| {
558574 // Insert default type params
559575 let mut g = generics. into_iter ( ) ;
@@ -649,13 +665,15 @@ pub(super) fn struct_projection<'a, DB: HirDatabase>(
649665 ctx : & ' a TermSearchCtx < ' a , DB > ,
650666 _defs : & ' a FxHashSet < ScopeDef > ,
651667 lookup : & ' a mut LookupTable ,
668+ should_continue : & ' a dyn std:: ops:: Fn ( ) -> bool ,
652669) -> impl Iterator < Item = Expr > + ' a {
653670 let db = ctx. sema . db ;
654671 let module = ctx. scope . module ( ) ;
655672 lookup
656673 . new_types ( NewTypesKey :: StructProjection )
657674 . into_iter ( )
658675 . map ( |ty| ( ty. clone ( ) , lookup. find ( db, & ty) . expect ( "Expr not in lookup" ) ) )
676+ . filter ( |_| should_continue ( ) )
659677 . flat_map ( move |( ty, targets) | {
660678 ty. fields ( db) . into_iter ( ) . filter_map ( move |( field, filed_ty) | {
661679 if !field. is_visible_from ( db, module) {
@@ -720,6 +738,7 @@ pub(super) fn impl_static_method<'a, DB: HirDatabase>(
720738 ctx : & ' a TermSearchCtx < ' a , DB > ,
721739 _defs : & ' a FxHashSet < ScopeDef > ,
722740 lookup : & ' a mut LookupTable ,
741+ should_continue : & ' a dyn std:: ops:: Fn ( ) -> bool ,
723742) -> impl Iterator < Item = Expr > + ' a {
724743 let db = ctx. sema . db ;
725744 let module = ctx. scope . module ( ) ;
@@ -728,6 +747,7 @@ pub(super) fn impl_static_method<'a, DB: HirDatabase>(
728747 . clone ( )
729748 . into_iter ( )
730749 . chain ( iter:: once ( ctx. goal . clone ( ) ) )
750+ . filter ( |_| should_continue ( ) )
731751 . flat_map ( |ty| {
732752 Impl :: all_for_type ( db, ty. clone ( ) ) . into_iter ( ) . map ( move |imp| ( ty. clone ( ) , imp) )
733753 } )
@@ -801,6 +821,7 @@ pub(super) fn impl_static_method<'a, DB: HirDatabase>(
801821 . permutations ( non_default_fn_type_params_len) ;
802822
803823 let exprs: Vec < _ > = generic_params
824+ . filter ( |_| should_continue ( ) )
804825 . filter_map ( |generics| {
805826 // Insert default type params
806827 let mut g = generics. into_iter ( ) ;
@@ -888,6 +909,7 @@ pub(super) fn make_tuple<'a, DB: HirDatabase>(
888909 ctx : & ' a TermSearchCtx < ' a , DB > ,
889910 _defs : & ' a FxHashSet < ScopeDef > ,
890911 lookup : & ' a mut LookupTable ,
912+ should_continue : & ' a dyn std:: ops:: Fn ( ) -> bool ,
891913) -> impl Iterator < Item = Expr > + ' a {
892914 let db = ctx. sema . db ;
893915 let module = ctx. scope . module ( ) ;
@@ -896,6 +918,7 @@ pub(super) fn make_tuple<'a, DB: HirDatabase>(
896918 . types_wishlist ( )
897919 . clone ( )
898920 . into_iter ( )
921+ . filter ( |_| should_continue ( ) )
899922 . filter ( |ty| ty. is_tuple ( ) )
900923 . filter_map ( move |ty| {
901924 // Double check to not contain unknown
@@ -915,6 +938,7 @@ pub(super) fn make_tuple<'a, DB: HirDatabase>(
915938 let exprs: Vec < Expr > = param_exprs
916939 . into_iter ( )
917940 . multi_cartesian_product ( )
941+ . filter ( |_| should_continue ( ) )
918942 . map ( |params| {
919943 let tys: Vec < Type > = params. iter ( ) . map ( |it| it. ty ( db) ) . collect ( ) ;
920944 let tuple_ty = Type :: new_tuple ( module. krate ( ) . into ( ) , & tys) ;
0 commit comments