@@ -643,18 +643,18 @@ impl<'a> Resolver<'a> {
643643        let  not_local_module = crate_name. name  != kw:: Crate ; 
644644        let  mut  worklist =
645645            vec ! [ ( start_module,  Vec :: <ast:: PathSegment >:: new( ) ,  true ,  not_local_module) ] ; 
646+         let  mut  worklist_via_import = vec ! [ ] ; 
646647
647-         while  let  Some ( ( in_module,  path_segments,  accessible,  in_module_is_extern) )  = worklist. pop ( ) 
648+         while  let  Some ( ( in_module,  path_segments,  accessible,  in_module_is_extern) )  =
649+             match  worklist. pop ( )  { 
650+                 None  => worklist_via_import. pop ( ) , 
651+                 Some ( x)  => Some ( x) , 
652+             } 
648653        { 
649654            // We have to visit module children in deterministic order to avoid 
650655            // instabilities in reported imports (#43552). 
651656            in_module. for_each_child ( self ,  |this,  ident,  ns,  name_binding| { 
652-                 // avoid imports entirely 
653-                 if  name_binding. is_import ( )  && !name_binding. is_extern_crate ( )  { 
654-                     return ; 
655-                 } 
656- 
657-                 // avoid non-importable candidates as well 
657+                 // avoid non-importable candidates 
658658                if  !name_binding. is_importable ( )  { 
659659                    return ; 
660660                } 
@@ -667,6 +667,17 @@ impl<'a> Resolver<'a> {
667667                    return ; 
668668                } 
669669
670+                 let  via_import = name_binding. is_import ( )  && !name_binding. is_extern_crate ( ) ; 
671+ 
672+                 // There is an assumption elsewhere that paths of variants are in the enum's 
673+                 // declaration and not imported. With this assumption, the variant component is 
674+                 // chopped and the rest of the path is assumed to be the enum's own path. For 
675+                 // errors where a variant is used as the type instead of the enum, this causes 
676+                 // funny looking invalid suggestions, i.e `foo` instead of `foo::MyEnum`. 
677+                 if  via_import && name_binding. is_possibly_imported_variant ( )  { 
678+                     return ; 
679+                 } 
680+ 
670681                // collect results based on the filter function 
671682                // avoid suggesting anything from the same module in which we are resolving 
672683                if  ident. name  == lookup_ident. name 
@@ -724,7 +735,8 @@ impl<'a> Resolver<'a> {
724735                        let  is_extern = in_module_is_extern || name_binding. is_extern_crate ( ) ; 
725736                        // add the module to the lookup 
726737                        if  seen_modules. insert ( module. def_id ( ) . unwrap ( ) )  { 
727-                             worklist. push ( ( module,  path_segments,  child_accessible,  is_extern) ) ; 
738+                             if  via_import {  & mut  worklist_via_import }  else  {  & mut  worklist } 
739+                                 . push ( ( module,  path_segments,  child_accessible,  is_extern) ) ; 
728740                        } 
729741                    } 
730742                } 
0 commit comments