@@ -101,12 +101,14 @@ pub(super) fn type_constructor<'a, DB: HirDatabase>(
101
101
ctx : & ' a TermSearchCtx < ' a , DB > ,
102
102
defs : & ' a FxHashSet < ScopeDef > ,
103
103
lookup : & ' a mut LookupTable ,
104
+ should_continue : & ' a dyn std:: ops:: Fn ( ) -> bool ,
104
105
) -> impl Iterator < Item = Expr > + ' a {
105
106
let db = ctx. sema . db ;
106
107
let module = ctx. scope . module ( ) ;
107
108
fn variant_helper (
108
109
db : & dyn HirDatabase ,
109
110
lookup : & mut LookupTable ,
111
+ should_continue : & dyn std:: ops:: Fn ( ) -> bool ,
110
112
parent_enum : Enum ,
111
113
variant : Variant ,
112
114
config : & TermSearchConfig ,
@@ -152,6 +154,7 @@ pub(super) fn type_constructor<'a, DB: HirDatabase>(
152
154
. chain ( ( non_default_type_params_len == 0 ) . then_some ( Vec :: new ( ) ) ) ;
153
155
154
156
generic_params
157
+ . filter ( |_| should_continue ( ) )
155
158
. filter_map ( move |generics| {
156
159
// Insert default type params
157
160
let mut g = generics. into_iter ( ) ;
@@ -194,8 +197,14 @@ pub(super) fn type_constructor<'a, DB: HirDatabase>(
194
197
defs. iter ( )
195
198
. filter_map ( move |def| match def {
196
199
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
+ ) ;
199
208
if variant_exprs. is_empty ( ) {
200
209
return None ;
201
210
}
@@ -213,7 +222,9 @@ pub(super) fn type_constructor<'a, DB: HirDatabase>(
213
222
let exprs: Vec < ( Type , Vec < Expr > ) > = enum_
214
223
. variants ( db)
215
224
. 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
+ } )
217
228
. collect ( ) ;
218
229
219
230
if exprs. is_empty ( ) {
@@ -271,6 +282,7 @@ pub(super) fn type_constructor<'a, DB: HirDatabase>(
271
282
. chain ( ( non_default_type_params_len == 0 ) . then_some ( Vec :: new ( ) ) ) ;
272
283
273
284
let exprs = generic_params
285
+ . filter ( |_| should_continue ( ) )
274
286
. filter_map ( |generics| {
275
287
// Insert default type params
276
288
let mut g = generics. into_iter ( ) ;
@@ -349,6 +361,7 @@ pub(super) fn free_function<'a, DB: HirDatabase>(
349
361
ctx : & ' a TermSearchCtx < ' a , DB > ,
350
362
defs : & ' a FxHashSet < ScopeDef > ,
351
363
lookup : & ' a mut LookupTable ,
364
+ should_continue : & ' a dyn std:: ops:: Fn ( ) -> bool ,
352
365
) -> impl Iterator < Item = Expr > + ' a {
353
366
let db = ctx. sema . db ;
354
367
let module = ctx. scope . module ( ) ;
@@ -390,6 +403,7 @@ pub(super) fn free_function<'a, DB: HirDatabase>(
390
403
. permutations ( non_default_type_params_len) ;
391
404
392
405
let exprs: Vec < _ > = generic_params
406
+ . filter ( |_| should_continue ( ) )
393
407
. filter_map ( |generics| {
394
408
// Insert default type params
395
409
let mut g = generics. into_iter ( ) ;
@@ -478,6 +492,7 @@ pub(super) fn impl_method<'a, DB: HirDatabase>(
478
492
ctx : & ' a TermSearchCtx < ' a , DB > ,
479
493
_defs : & ' a FxHashSet < ScopeDef > ,
480
494
lookup : & ' a mut LookupTable ,
495
+ should_continue : & ' a dyn std:: ops:: Fn ( ) -> bool ,
481
496
) -> impl Iterator < Item = Expr > + ' a {
482
497
let db = ctx. sema . db ;
483
498
let module = ctx. scope . module ( ) ;
@@ -554,6 +569,7 @@ pub(super) fn impl_method<'a, DB: HirDatabase>(
554
569
. permutations ( non_default_fn_type_params_len) ;
555
570
556
571
let exprs: Vec < _ > = generic_params
572
+ . filter ( |_| should_continue ( ) )
557
573
. filter_map ( |generics| {
558
574
// Insert default type params
559
575
let mut g = generics. into_iter ( ) ;
@@ -649,13 +665,15 @@ pub(super) fn struct_projection<'a, DB: HirDatabase>(
649
665
ctx : & ' a TermSearchCtx < ' a , DB > ,
650
666
_defs : & ' a FxHashSet < ScopeDef > ,
651
667
lookup : & ' a mut LookupTable ,
668
+ should_continue : & ' a dyn std:: ops:: Fn ( ) -> bool ,
652
669
) -> impl Iterator < Item = Expr > + ' a {
653
670
let db = ctx. sema . db ;
654
671
let module = ctx. scope . module ( ) ;
655
672
lookup
656
673
. new_types ( NewTypesKey :: StructProjection )
657
674
. into_iter ( )
658
675
. map ( |ty| ( ty. clone ( ) , lookup. find ( db, & ty) . expect ( "Expr not in lookup" ) ) )
676
+ . filter ( |_| should_continue ( ) )
659
677
. flat_map ( move |( ty, targets) | {
660
678
ty. fields ( db) . into_iter ( ) . filter_map ( move |( field, filed_ty) | {
661
679
if !field. is_visible_from ( db, module) {
@@ -720,6 +738,7 @@ pub(super) fn impl_static_method<'a, DB: HirDatabase>(
720
738
ctx : & ' a TermSearchCtx < ' a , DB > ,
721
739
_defs : & ' a FxHashSet < ScopeDef > ,
722
740
lookup : & ' a mut LookupTable ,
741
+ should_continue : & ' a dyn std:: ops:: Fn ( ) -> bool ,
723
742
) -> impl Iterator < Item = Expr > + ' a {
724
743
let db = ctx. sema . db ;
725
744
let module = ctx. scope . module ( ) ;
@@ -728,6 +747,7 @@ pub(super) fn impl_static_method<'a, DB: HirDatabase>(
728
747
. clone ( )
729
748
. into_iter ( )
730
749
. chain ( iter:: once ( ctx. goal . clone ( ) ) )
750
+ . filter ( |_| should_continue ( ) )
731
751
. flat_map ( |ty| {
732
752
Impl :: all_for_type ( db, ty. clone ( ) ) . into_iter ( ) . map ( move |imp| ( ty. clone ( ) , imp) )
733
753
} )
@@ -801,6 +821,7 @@ pub(super) fn impl_static_method<'a, DB: HirDatabase>(
801
821
. permutations ( non_default_fn_type_params_len) ;
802
822
803
823
let exprs: Vec < _ > = generic_params
824
+ . filter ( |_| should_continue ( ) )
804
825
. filter_map ( |generics| {
805
826
// Insert default type params
806
827
let mut g = generics. into_iter ( ) ;
@@ -888,6 +909,7 @@ pub(super) fn make_tuple<'a, DB: HirDatabase>(
888
909
ctx : & ' a TermSearchCtx < ' a , DB > ,
889
910
_defs : & ' a FxHashSet < ScopeDef > ,
890
911
lookup : & ' a mut LookupTable ,
912
+ should_continue : & ' a dyn std:: ops:: Fn ( ) -> bool ,
891
913
) -> impl Iterator < Item = Expr > + ' a {
892
914
let db = ctx. sema . db ;
893
915
let module = ctx. scope . module ( ) ;
@@ -896,6 +918,7 @@ pub(super) fn make_tuple<'a, DB: HirDatabase>(
896
918
. types_wishlist ( )
897
919
. clone ( )
898
920
. into_iter ( )
921
+ . filter ( |_| should_continue ( ) )
899
922
. filter ( |ty| ty. is_tuple ( ) )
900
923
. filter_map ( move |ty| {
901
924
// Double check to not contain unknown
@@ -915,6 +938,7 @@ pub(super) fn make_tuple<'a, DB: HirDatabase>(
915
938
let exprs: Vec < Expr > = param_exprs
916
939
. into_iter ( )
917
940
. multi_cartesian_product ( )
941
+ . filter ( |_| should_continue ( ) )
918
942
. map ( |params| {
919
943
let tys: Vec < Type > = params. iter ( ) . map ( |it| it. ty ( db) ) . collect ( ) ;
920
944
let tuple_ty = Type :: new_tuple ( module. krate ( ) . into ( ) , & tys) ;
0 commit comments