@@ -121,8 +121,8 @@ impl<'genv, 'tcx> CrateResolver<'genv, 'tcx> {
121121 let mut definitions = DefinitionMap :: default ( ) ;
122122 for ( parent, items) in & self . specs . flux_items_by_parent {
123123 for item in items {
124- // NOTE: This is putting all items in the same namespace. We could have qualifiers
125- // in a different namespace.
124+ // NOTE: This is putting all items in the same namespace. In principle, we could have
125+ // qualifiers in a different namespace.
126126 definitions
127127 . define ( item. name ( ) )
128128 . emit ( & self . genv )
@@ -191,8 +191,8 @@ impl<'genv, 'tcx> CrateResolver<'genv, 'tcx> {
191191 hir:: UseKind :: Glob => {
192192 let is_prelude = is_prelude_import ( self . genv . tcx ( ) , item) ;
193193 for mod_child in self . glob_imports ( path) {
194- if let Some ( ns @ ( TypeNS | ValueNS ) ) = mod_child. res . ns ( )
195- && let Ok ( res ) = fhir :: Res :: try_from ( mod_child . res )
194+ if let Ok ( res ) = fhir :: Res :: try_from ( mod_child. res )
195+ && let Some ( ns @ ( TypeNS | ValueNS ) ) = res. ns ( )
196196 {
197197 let name = mod_child. ident . name ;
198198 if is_prelude {
@@ -495,14 +495,23 @@ impl<'genv, 'tcx> CrateResolver<'genv, 'tcx> {
495495 }
496496
497497 fn glob_imports (
498- & self ,
498+ & mut self ,
499499 path : & hir:: UsePath ,
500500 ) -> impl Iterator < Item = & ' tcx ModChild > + use < ' tcx > {
501- let res = path. segments . last ( ) . unwrap ( ) . res ;
502-
501+ // The path for the prelude import is not resolved anymore after <https://github.com/rust-lang/rust/pull/145322>,
502+ // so we resolve all paths here. If this ever causes problems, we could use the resolution in the `UsePath` for
503+ // non-prelude glob imports.
503504 let tcx = self . genv . tcx ( ) ;
504505 let curr_mod = self . current_module . to_def_id ( ) ;
505- if let hir:: def:: Res :: Def ( DefKind :: Mod , module_id) = res { Some ( module_id) } else { None }
506+ self . resolve_path_with_ribs ( path. segments , TypeNS )
507+ . and_then ( |partial_res| partial_res. full_res ( ) )
508+ . and_then ( |res| {
509+ if let fhir:: Res :: Def ( DefKind :: Mod , module_id) = res {
510+ Some ( module_id)
511+ } else {
512+ None
513+ }
514+ } )
506515 . into_iter ( )
507516 . flat_map ( move |module_id| visible_module_children ( tcx, module_id, curr_mod) )
508517 }
@@ -517,8 +526,11 @@ impl<'genv, 'tcx> CrateResolver<'genv, 'tcx> {
517526 match module. kind {
518527 ModuleKind :: Mod => {
519528 let module_id = module. def_id ;
520- visible_module_children ( tcx, module_id, self . current_module . to_def_id ( ) )
521- . find ( |child| child. res . matches_ns ( ns) && child. ident == ident)
529+ let current_mod = self . current_module . to_def_id ( ) ;
530+ visible_module_children ( tcx, module_id, current_mod)
531+ . find ( |child| {
532+ child. res . matches_ns ( ns) && tcx. hygienic_eq ( ident, child. ident , current_mod)
533+ } )
522534 . and_then ( |child| fhir:: Res :: try_from ( child. res ) . ok ( ) )
523535 }
524536 ModuleKind :: Trait => {
@@ -702,6 +714,7 @@ impl<'tcx> hir::intravisit::Visitor<'tcx> for CrateResolver<'_, 'tcx> {
702714}
703715
704716/// Akin to `rustc_resolve::Module` but specialized to what we support
717+ #[ derive( Debug ) ]
705718struct Module {
706719 kind : ModuleKind ,
707720 def_id : DefId ,
@@ -714,6 +727,7 @@ impl Module {
714727}
715728
716729/// Akin to `rustc_resolve::ModuleKind` but specialized to what we support
730+ #[ derive( Debug ) ]
717731enum ModuleKind {
718732 Mod ,
719733 Trait ,
@@ -767,7 +781,8 @@ fn is_prelude_import(tcx: TyCtxt, item: &hir::Item) -> bool {
767781 . any ( |attr| attr. path_matches ( & [ sym:: prelude_import] ) )
768782}
769783
770- /// Abstraction over [`surface::PathSegment`] and [`surface::ExprPathSegment`]
784+ /// Abstraction over a "segment" so we can use [`CrateResolver::resolve_path_with_ribs`] with paths
785+ /// from different sources (e.g., [`surface::PathSegment`], [`surface::ExprPathSegment`])
771786trait Segment : std:: fmt:: Debug {
772787 fn record_segment_res ( resolver : & mut CrateResolver , segment : & Self , res : fhir:: Res ) ;
773788 fn ident ( & self ) -> Ident ;
@@ -802,6 +817,14 @@ impl Segment for Ident {
802817 }
803818}
804819
820+ impl Segment for hir:: PathSegment < ' _ > {
821+ fn record_segment_res ( _resolver : & mut CrateResolver , _segment : & Self , _res : fhir:: Res ) { }
822+
823+ fn ident ( & self ) -> Ident {
824+ self . ident
825+ }
826+ }
827+
805828struct ItemResolver < ' a , ' genv , ' tcx > {
806829 resolver : & ' a mut CrateResolver < ' genv , ' tcx > ,
807830 opaque : Option < LocalDefId > , // TODO: HACK! need to generalize to multiple opaque types/impls in a signature.
0 commit comments