@@ -965,6 +965,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
965965 // if it can then our result is not determined and can be invalidated.
966966 for single_import in & resolution. single_imports {
967967 let Some ( import_vis) = single_import. vis . get ( ) else {
968+ // This branch handles a cycle in single imports, which occurs
969+ // when we've previously captured the `vis` value during an import
970+ // process.
971+ //
972+ // For example:
973+ // ```
974+ // use a::b;
975+ // use b as a;
976+ // ```
977+ // 1. Steal the `vis` in `use a::b` and attempt to locate `a` in the
978+ // current module.
979+ // 2. Encounter the import `use b as a`, which is a `single_import` for `a`,
980+ // and try to find `b` in the current module.
981+ // 3. Re-encounter the `use a::b` import since it's a `single_import` of `b`.
982+ // This leads to entering this branch.
968983 continue ;
969984 } ;
970985 if !self . is_accessible_from ( import_vis, parent_scope. module ) {
@@ -979,15 +994,22 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
979994 // named imports.
980995 continue ;
981996 }
997+
982998 let Some ( module) = single_import. imported_module . get ( ) else {
983999 return Err ( ( Undetermined , Weak :: No ) ) ;
9841000 } ;
985- let ImportKind :: Single { source : ident, .. } = single_import. kind else {
1001+ let ImportKind :: Single { source : ident, source_bindings, .. } = & single_import. kind
1002+ else {
9861003 unreachable ! ( ) ;
9871004 } ;
1005+ if binding. map_or ( false , |binding| binding. module ( ) . is_some ( ) )
1006+ && source_bindings. iter ( ) . all ( |binding| matches ! ( binding. get( ) , Err ( Undetermined ) ) )
1007+ {
1008+ return Err ( ( Undetermined , Weak :: No ) ) ;
1009+ }
9881010 match self . resolve_ident_in_module (
9891011 module,
990- ident,
1012+ * ident,
9911013 ns,
9921014 & single_import. parent_scope ,
9931015 None ,
0 commit comments