@@ -5219,49 +5219,25 @@ impl Type {
5219
5219
traits_in_scope : & FxHashSet < TraitId > ,
5220
5220
with_local_impls : Option < Module > ,
5221
5221
name : Option < & Name > ,
5222
- callback : impl FnMut ( Function ) -> Option < T > ,
5222
+ mut callback : impl FnMut ( Function ) -> Option < T > ,
5223
5223
) -> Option < T > {
5224
- struct Callback < T , F > {
5225
- f : F ,
5226
- slot : Option < T > ,
5227
- }
5228
- impl < T , F > MethodCandidateCallback for & ' _ mut Callback < T , F >
5229
- where
5230
- F : FnMut ( Function ) -> Option < T > ,
5231
- {
5232
- fn on_inherent_method ( & mut self , f : Function ) -> ControlFlow < ( ) > {
5233
- match ( self . f ) ( f) {
5234
- it @ Some ( _) => {
5235
- self . slot = it;
5236
- ControlFlow :: Break ( ( ) )
5237
- }
5238
- None => ControlFlow :: Continue ( ( ) ) ,
5239
- }
5240
- }
5241
-
5242
- fn on_trait_method ( & mut self , f : Function ) -> ControlFlow < ( ) > {
5243
- match ( self . f ) ( f) {
5244
- it @ Some ( _) => {
5245
- self . slot = it;
5246
- ControlFlow :: Break ( ( ) )
5247
- }
5248
- None => ControlFlow :: Continue ( ( ) ) ,
5249
- }
5250
- }
5251
- }
5252
-
5253
5224
let _p = tracing:: info_span!( "iterate_method_candidates_with_traits" ) . entered ( ) ;
5254
- let mut callback = Callback { slot : None , f : callback } ;
5255
-
5225
+ let mut slot = None ;
5256
5226
self . iterate_method_candidates_split_inherent (
5257
5227
db,
5258
5228
scope,
5259
5229
traits_in_scope,
5260
5230
with_local_impls,
5261
5231
name,
5262
- & mut callback,
5232
+ |f| match callback ( f) {
5233
+ it @ Some ( _) => {
5234
+ slot = it;
5235
+ ControlFlow :: Break ( ( ) )
5236
+ }
5237
+ None => ControlFlow :: Continue ( ( ) ) ,
5238
+ } ,
5263
5239
) ;
5264
- callback . slot
5240
+ slot
5265
5241
}
5266
5242
5267
5243
pub fn iterate_method_candidates < T > (
@@ -5361,49 +5337,26 @@ impl Type {
5361
5337
traits_in_scope : & FxHashSet < TraitId > ,
5362
5338
with_local_impls : Option < Module > ,
5363
5339
name : Option < & Name > ,
5364
- callback : impl FnMut ( AssocItem ) -> Option < T > ,
5340
+ mut callback : impl FnMut ( AssocItem ) -> Option < T > ,
5365
5341
) -> Option < T > {
5366
- struct Callback < T , F > {
5367
- f : F ,
5368
- slot : Option < T > ,
5369
- }
5370
- impl < T , F > PathCandidateCallback for & ' _ mut Callback < T , F >
5371
- where
5372
- F : FnMut ( AssocItem ) -> Option < T > ,
5373
- {
5374
- fn on_inherent_item ( & mut self , item : AssocItem ) -> ControlFlow < ( ) > {
5375
- match ( self . f ) ( item) {
5376
- it @ Some ( _) => {
5377
- self . slot = it;
5378
- ControlFlow :: Break ( ( ) )
5379
- }
5380
- None => ControlFlow :: Continue ( ( ) ) ,
5381
- }
5382
- }
5383
-
5384
- fn on_trait_item ( & mut self , item : AssocItem ) -> ControlFlow < ( ) > {
5385
- match ( self . f ) ( item) {
5386
- it @ Some ( _) => {
5387
- self . slot = it;
5388
- ControlFlow :: Break ( ( ) )
5389
- }
5390
- None => ControlFlow :: Continue ( ( ) ) ,
5391
- }
5392
- }
5393
- }
5394
-
5395
5342
let _p = tracing:: info_span!( "iterate_path_candidates" ) . entered ( ) ;
5396
- let mut callback = Callback { slot : None , f : callback } ;
5343
+ let mut slot = None ;
5397
5344
5398
5345
self . iterate_path_candidates_split_inherent (
5399
5346
db,
5400
5347
scope,
5401
5348
traits_in_scope,
5402
5349
with_local_impls,
5403
5350
name,
5404
- & mut callback,
5351
+ |item| match callback ( item) {
5352
+ it @ Some ( _) => {
5353
+ slot = it;
5354
+ ControlFlow :: Break ( ( ) )
5355
+ }
5356
+ None => ControlFlow :: Continue ( ( ) ) ,
5357
+ } ,
5405
5358
) ;
5406
- callback . slot
5359
+ slot
5407
5360
}
5408
5361
5409
5362
/// Iterates over inherent methods.
@@ -6167,8 +6120,34 @@ pub trait MethodCandidateCallback {
6167
6120
fn on_trait_method ( & mut self , f : Function ) -> ControlFlow < ( ) > ;
6168
6121
}
6169
6122
6123
+ impl < F > MethodCandidateCallback for F
6124
+ where
6125
+ F : FnMut ( Function ) -> ControlFlow < ( ) > ,
6126
+ {
6127
+ fn on_inherent_method ( & mut self , f : Function ) -> ControlFlow < ( ) > {
6128
+ self ( f)
6129
+ }
6130
+
6131
+ fn on_trait_method ( & mut self , f : Function ) -> ControlFlow < ( ) > {
6132
+ self ( f)
6133
+ }
6134
+ }
6135
+
6170
6136
pub trait PathCandidateCallback {
6171
6137
fn on_inherent_item ( & mut self , item : AssocItem ) -> ControlFlow < ( ) > ;
6172
6138
6173
6139
fn on_trait_item ( & mut self , item : AssocItem ) -> ControlFlow < ( ) > ;
6174
6140
}
6141
+
6142
+ impl < F > PathCandidateCallback for F
6143
+ where
6144
+ F : FnMut ( AssocItem ) -> ControlFlow < ( ) > ,
6145
+ {
6146
+ fn on_inherent_item ( & mut self , item : AssocItem ) -> ControlFlow < ( ) > {
6147
+ self ( item)
6148
+ }
6149
+
6150
+ fn on_trait_item ( & mut self , item : AssocItem ) -> ControlFlow < ( ) > {
6151
+ self ( item)
6152
+ }
6153
+ }
0 commit comments