@@ -395,9 +395,8 @@ impl DefCollector<'_> {
395395 // As some of the macros will expand newly import shadowing partial resolved imports
396396 // FIXME: We maybe could skip this, if we handle the indeterminate imports in `resolve_imports`
397397 // correctly
398- let partial_resolved = self . indeterminate_imports . drain ( ..) . filter_map ( |mut directive| {
399- directive. status = PartialResolvedImport :: Unresolved ;
400- Some ( directive)
398+ let partial_resolved = self . indeterminate_imports . drain ( ..) . map ( |directive| {
399+ ImportDirective { status : PartialResolvedImport :: Unresolved , ..directive }
401400 } ) ;
402401 self . unresolved_imports . extend ( partial_resolved) ;
403402 self . resolve_imports ( ) ;
@@ -434,50 +433,48 @@ impl DefCollector<'_> {
434433 fn reseed_with_unresolved_attribute ( & mut self ) -> ReachedFixedPoint {
435434 cov_mark:: hit!( unresolved_attribute_fallback) ;
436435
437- let mut unresolved_macros = mem:: take ( & mut self . unresolved_macros ) ;
438- let pos = unresolved_macros. iter ( ) . position ( |directive| {
439- if let MacroDirectiveKind :: Attr { ast_id, mod_item, attr, tree } = & directive. kind {
440- self . def_map . diagnostics . push ( DefDiagnostic :: unresolved_macro_call (
441- directive. module_id ,
442- MacroCallKind :: Attr {
443- ast_id : ast_id. ast_id ,
444- attr_args : Default :: default ( ) ,
445- invoc_attr_index : attr. id . ast_index ,
446- is_derive : false ,
447- } ,
448- attr. path ( ) . clone ( ) ,
449- ) ) ;
436+ let unresolved_attr =
437+ self . unresolved_macros . iter ( ) . enumerate ( ) . find_map ( |( idx, directive) | match & directive
438+ . kind
439+ {
440+ MacroDirectiveKind :: Attr { ast_id, mod_item, attr, tree } => {
441+ self . def_map . diagnostics . push ( DefDiagnostic :: unresolved_macro_call (
442+ directive. module_id ,
443+ MacroCallKind :: Attr {
444+ ast_id : ast_id. ast_id ,
445+ attr_args : Default :: default ( ) ,
446+ invoc_attr_index : attr. id . ast_index ,
447+ is_derive : false ,
448+ } ,
449+ attr. path ( ) . clone ( ) ,
450+ ) ) ;
450451
451- self . skip_attrs . insert ( ast_id. ast_id . with_value ( * mod_item) , attr. id ) ;
452+ self . skip_attrs . insert ( ast_id. ast_id . with_value ( * mod_item) , attr. id ) ;
452453
453- let item_tree = tree. item_tree ( self . db ) ;
454- let mod_dir = self . mod_dirs [ & directive. module_id ] . clone ( ) ;
454+ Some ( ( idx, directive, * mod_item, * tree) )
455+ }
456+ _ => None ,
457+ } ) ;
458+
459+ match unresolved_attr {
460+ Some ( ( pos, & MacroDirective { module_id, depth, container, .. } , mod_item, tree_id) ) => {
461+ let item_tree = & tree_id. item_tree ( self . db ) ;
462+ let mod_dir = self . mod_dirs [ & module_id] . clone ( ) ;
455463 ModCollector {
456464 def_collector : self ,
457- macro_depth : directive . depth ,
458- module_id : directive . module_id ,
459- tree_id : * tree ,
460- item_tree : & item_tree ,
465+ macro_depth : depth,
466+ module_id,
467+ tree_id,
468+ item_tree,
461469 mod_dir,
462470 }
463- . collect ( & [ * mod_item] , directive. container ) ;
464- true
465- } else {
466- false
467- }
468- } ) ;
469-
470- if let Some ( pos) = pos {
471- unresolved_macros. swap_remove ( pos) ;
472- }
473-
474- self . unresolved_macros . extend ( unresolved_macros) ;
471+ . collect ( & [ mod_item] , container) ;
475472
476- if pos . is_some ( ) {
477- // Continue name resolution with the new data.
478- ReachedFixedPoint :: No
479- } else {
480- ReachedFixedPoint :: Yes
473+ self . unresolved_macros . swap_remove ( pos ) ;
474+ // Continue name resolution with the new data.
475+ ReachedFixedPoint :: No
476+ }
477+ None => ReachedFixedPoint :: Yes ,
481478 }
482479 }
483480
@@ -722,7 +719,8 @@ impl DefCollector<'_> {
722719 fn resolve_imports ( & mut self ) -> ReachedFixedPoint {
723720 let mut res = ReachedFixedPoint :: Yes ;
724721 let imports = mem:: take ( & mut self . unresolved_imports ) ;
725- let imports = imports
722+
723+ self . unresolved_imports = imports
726724 . into_iter ( )
727725 . filter_map ( |mut directive| {
728726 directive. status = self . resolve_import ( directive. module_id , & directive. import ) ;
@@ -742,7 +740,6 @@ impl DefCollector<'_> {
742740 }
743741 } )
744742 . collect ( ) ;
745- self . unresolved_imports = imports;
746743 res
747744 }
748745
@@ -1034,7 +1031,7 @@ impl DefCollector<'_> {
10341031 . glob_imports
10351032 . get ( & module_id)
10361033 . into_iter ( )
1037- . flat_map ( |v| v . iter ( ) )
1034+ . flatten ( )
10381035 . filter ( |( glob_importing_module, _) | {
10391036 // we know all resolutions have the same visibility (`vis`), so we
10401037 // just need to check that once
0 commit comments