@@ -127,7 +127,15 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
127
127
None => continue ,
128
128
} ;
129
129
let def_map = module. def_map ( & db) ;
130
- visit_module ( & db, & def_map, module. local_id , & mut |it| defs. push ( it) ) ;
130
+ visit_module ( & db, & def_map, module. local_id , & mut |it| {
131
+ defs. push ( match it {
132
+ ModuleDefId :: FunctionId ( it) => it. into ( ) ,
133
+ ModuleDefId :: EnumVariantId ( it) => it. into ( ) ,
134
+ ModuleDefId :: ConstId ( it) => it. into ( ) ,
135
+ ModuleDefId :: StaticId ( it) => it. into ( ) ,
136
+ _ => return ,
137
+ } )
138
+ } ) ;
131
139
}
132
140
defs. sort_by_key ( |def| match def {
133
141
DefWithBodyId :: FunctionId ( it) => {
@@ -375,7 +383,15 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
375
383
let def_map = module. def_map ( & db) ;
376
384
377
385
let mut defs: Vec < DefWithBodyId > = Vec :: new ( ) ;
378
- visit_module ( & db, & def_map, module. local_id , & mut |it| defs. push ( it) ) ;
386
+ visit_module ( & db, & def_map, module. local_id , & mut |it| {
387
+ defs. push ( match it {
388
+ ModuleDefId :: FunctionId ( it) => it. into ( ) ,
389
+ ModuleDefId :: EnumVariantId ( it) => it. into ( ) ,
390
+ ModuleDefId :: ConstId ( it) => it. into ( ) ,
391
+ ModuleDefId :: StaticId ( it) => it. into ( ) ,
392
+ _ => return ,
393
+ } )
394
+ } ) ;
379
395
defs. sort_by_key ( |def| match def {
380
396
DefWithBodyId :: FunctionId ( it) => {
381
397
let loc = it. lookup ( & db) ;
@@ -405,30 +421,30 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
405
421
buf
406
422
}
407
423
408
- fn visit_module (
424
+ pub ( crate ) fn visit_module (
409
425
db : & TestDB ,
410
426
crate_def_map : & DefMap ,
411
427
module_id : LocalModuleId ,
412
- cb : & mut dyn FnMut ( DefWithBodyId ) ,
428
+ cb : & mut dyn FnMut ( ModuleDefId ) ,
413
429
) {
414
430
visit_scope ( db, crate_def_map, & crate_def_map[ module_id] . scope , cb) ;
415
431
for impl_id in crate_def_map[ module_id] . scope . impls ( ) {
416
432
let impl_data = db. impl_data ( impl_id) ;
417
433
for & item in impl_data. items . iter ( ) {
418
434
match item {
419
435
AssocItemId :: FunctionId ( it) => {
420
- let def = it. into ( ) ;
421
- cb ( def) ;
422
- let body = db. body ( def) ;
436
+ let body = db. body ( it. into ( ) ) ;
437
+ cb ( it. into ( ) ) ;
423
438
visit_body ( db, & body, cb) ;
424
439
}
425
440
AssocItemId :: ConstId ( it) => {
426
- let def = it. into ( ) ;
427
- cb ( def) ;
428
- let body = db. body ( def) ;
441
+ let body = db. body ( it. into ( ) ) ;
442
+ cb ( it. into ( ) ) ;
429
443
visit_body ( db, & body, cb) ;
430
444
}
431
- AssocItemId :: TypeAliasId ( _) => ( ) ,
445
+ AssocItemId :: TypeAliasId ( it) => {
446
+ cb ( it. into ( ) ) ;
447
+ }
432
448
}
433
449
}
434
450
}
@@ -437,33 +453,27 @@ fn visit_module(
437
453
db : & TestDB ,
438
454
crate_def_map : & DefMap ,
439
455
scope : & ItemScope ,
440
- cb : & mut dyn FnMut ( DefWithBodyId ) ,
456
+ cb : & mut dyn FnMut ( ModuleDefId ) ,
441
457
) {
442
458
for decl in scope. declarations ( ) {
459
+ cb ( decl) ;
443
460
match decl {
444
461
ModuleDefId :: FunctionId ( it) => {
445
- let def = it. into ( ) ;
446
- cb ( def) ;
447
- let body = db. body ( def) ;
462
+ let body = db. body ( it. into ( ) ) ;
448
463
visit_body ( db, & body, cb) ;
449
464
}
450
465
ModuleDefId :: ConstId ( it) => {
451
- let def = it. into ( ) ;
452
- cb ( def) ;
453
- let body = db. body ( def) ;
466
+ let body = db. body ( it. into ( ) ) ;
454
467
visit_body ( db, & body, cb) ;
455
468
}
456
469
ModuleDefId :: StaticId ( it) => {
457
- let def = it. into ( ) ;
458
- cb ( def) ;
459
- let body = db. body ( def) ;
470
+ let body = db. body ( it. into ( ) ) ;
460
471
visit_body ( db, & body, cb) ;
461
472
}
462
473
ModuleDefId :: AdtId ( hir_def:: AdtId :: EnumId ( it) ) => {
463
474
db. enum_data ( it) . variants . iter ( ) . for_each ( |& ( it, _) | {
464
- let def = it. into ( ) ;
465
- cb ( def) ;
466
- let body = db. body ( def) ;
475
+ let body = db. body ( it. into ( ) ) ;
476
+ cb ( it. into ( ) ) ;
467
477
visit_body ( db, & body, cb) ;
468
478
} ) ;
469
479
}
@@ -473,7 +483,7 @@ fn visit_module(
473
483
match item {
474
484
AssocItemId :: FunctionId ( it) => cb ( it. into ( ) ) ,
475
485
AssocItemId :: ConstId ( it) => cb ( it. into ( ) ) ,
476
- AssocItemId :: TypeAliasId ( _ ) => ( ) ,
486
+ AssocItemId :: TypeAliasId ( it ) => cb ( it . into ( ) ) ,
477
487
}
478
488
}
479
489
}
@@ -483,7 +493,7 @@ fn visit_module(
483
493
}
484
494
}
485
495
486
- fn visit_body ( db : & TestDB , body : & Body , cb : & mut dyn FnMut ( DefWithBodyId ) ) {
496
+ fn visit_body ( db : & TestDB , body : & Body , cb : & mut dyn FnMut ( ModuleDefId ) ) {
487
497
for ( _, def_map) in body. blocks ( db) {
488
498
for ( mod_id, _) in def_map. modules ( ) {
489
499
visit_module ( db, & def_map, mod_id, cb) ;
@@ -553,7 +563,13 @@ fn salsa_bug() {
553
563
let module = db. module_for_file ( pos. file_id ) ;
554
564
let crate_def_map = module. def_map ( & db) ;
555
565
visit_module ( & db, & crate_def_map, module. local_id , & mut |def| {
556
- db. infer ( def) ;
566
+ db. infer ( match def {
567
+ ModuleDefId :: FunctionId ( it) => it. into ( ) ,
568
+ ModuleDefId :: EnumVariantId ( it) => it. into ( ) ,
569
+ ModuleDefId :: ConstId ( it) => it. into ( ) ,
570
+ ModuleDefId :: StaticId ( it) => it. into ( ) ,
571
+ _ => return ,
572
+ } ) ;
557
573
} ) ;
558
574
559
575
let new_text = "
@@ -586,6 +602,12 @@ fn salsa_bug() {
586
602
let module = db. module_for_file ( pos. file_id ) ;
587
603
let crate_def_map = module. def_map ( & db) ;
588
604
visit_module ( & db, & crate_def_map, module. local_id , & mut |def| {
589
- db. infer ( def) ;
605
+ db. infer ( match def {
606
+ ModuleDefId :: FunctionId ( it) => it. into ( ) ,
607
+ ModuleDefId :: EnumVariantId ( it) => it. into ( ) ,
608
+ ModuleDefId :: ConstId ( it) => it. into ( ) ,
609
+ ModuleDefId :: StaticId ( it) => it. into ( ) ,
610
+ _ => return ,
611
+ } ) ;
590
612
} ) ;
591
613
}
0 commit comments