@@ -127,7 +127,15 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
127127 None => continue ,
128128 } ;
129129 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+ } ) ;
131139 }
132140 defs. sort_by_key ( |def| match def {
133141 DefWithBodyId :: FunctionId ( it) => {
@@ -375,7 +383,15 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
375383 let def_map = module. def_map ( & db) ;
376384
377385 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+ } ) ;
379395 defs. sort_by_key ( |def| match def {
380396 DefWithBodyId :: FunctionId ( it) => {
381397 let loc = it. lookup ( & db) ;
@@ -405,30 +421,30 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
405421 buf
406422}
407423
408- fn visit_module (
424+ pub ( crate ) fn visit_module (
409425 db : & TestDB ,
410426 crate_def_map : & DefMap ,
411427 module_id : LocalModuleId ,
412- cb : & mut dyn FnMut ( DefWithBodyId ) ,
428+ cb : & mut dyn FnMut ( ModuleDefId ) ,
413429) {
414430 visit_scope ( db, crate_def_map, & crate_def_map[ module_id] . scope , cb) ;
415431 for impl_id in crate_def_map[ module_id] . scope . impls ( ) {
416432 let impl_data = db. impl_data ( impl_id) ;
417433 for & item in impl_data. items . iter ( ) {
418434 match item {
419435 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 ( ) ) ;
423438 visit_body ( db, & body, cb) ;
424439 }
425440 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 ( ) ) ;
429443 visit_body ( db, & body, cb) ;
430444 }
431- AssocItemId :: TypeAliasId ( _) => ( ) ,
445+ AssocItemId :: TypeAliasId ( it) => {
446+ cb ( it. into ( ) ) ;
447+ }
432448 }
433449 }
434450 }
@@ -437,33 +453,27 @@ fn visit_module(
437453 db : & TestDB ,
438454 crate_def_map : & DefMap ,
439455 scope : & ItemScope ,
440- cb : & mut dyn FnMut ( DefWithBodyId ) ,
456+ cb : & mut dyn FnMut ( ModuleDefId ) ,
441457 ) {
442458 for decl in scope. declarations ( ) {
459+ cb ( decl) ;
443460 match decl {
444461 ModuleDefId :: FunctionId ( it) => {
445- let def = it. into ( ) ;
446- cb ( def) ;
447- let body = db. body ( def) ;
462+ let body = db. body ( it. into ( ) ) ;
448463 visit_body ( db, & body, cb) ;
449464 }
450465 ModuleDefId :: ConstId ( it) => {
451- let def = it. into ( ) ;
452- cb ( def) ;
453- let body = db. body ( def) ;
466+ let body = db. body ( it. into ( ) ) ;
454467 visit_body ( db, & body, cb) ;
455468 }
456469 ModuleDefId :: StaticId ( it) => {
457- let def = it. into ( ) ;
458- cb ( def) ;
459- let body = db. body ( def) ;
470+ let body = db. body ( it. into ( ) ) ;
460471 visit_body ( db, & body, cb) ;
461472 }
462473 ModuleDefId :: AdtId ( hir_def:: AdtId :: EnumId ( it) ) => {
463474 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 ( ) ) ;
467477 visit_body ( db, & body, cb) ;
468478 } ) ;
469479 }
@@ -473,7 +483,7 @@ fn visit_module(
473483 match item {
474484 AssocItemId :: FunctionId ( it) => cb ( it. into ( ) ) ,
475485 AssocItemId :: ConstId ( it) => cb ( it. into ( ) ) ,
476- AssocItemId :: TypeAliasId ( _ ) => ( ) ,
486+ AssocItemId :: TypeAliasId ( it ) => cb ( it . into ( ) ) ,
477487 }
478488 }
479489 }
@@ -483,7 +493,7 @@ fn visit_module(
483493 }
484494 }
485495
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 ) ) {
487497 for ( _, def_map) in body. blocks ( db) {
488498 for ( mod_id, _) in def_map. modules ( ) {
489499 visit_module ( db, & def_map, mod_id, cb) ;
@@ -553,7 +563,13 @@ fn salsa_bug() {
553563 let module = db. module_for_file ( pos. file_id ) ;
554564 let crate_def_map = module. def_map ( & db) ;
555565 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+ } ) ;
557573 } ) ;
558574
559575 let new_text = "
@@ -586,6 +602,12 @@ fn salsa_bug() {
586602 let module = db. module_for_file ( pos. file_id ) ;
587603 let crate_def_map = module. def_map ( & db) ;
588604 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+ } ) ;
590612 } ) ;
591613}
0 commit comments