@@ -643,18 +643,18 @@ impl<'a> Resolver<'a> {
643
643
let not_local_module = crate_name. name != kw:: Crate ;
644
644
let mut worklist =
645
645
vec ! [ ( start_module, Vec :: <ast:: PathSegment >:: new( ) , true , not_local_module) ] ;
646
+ let mut worklist_via_import = vec ! [ ] ;
646
647
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
+ }
648
653
{
649
654
// We have to visit module children in deterministic order to avoid
650
655
// instabilities in reported imports (#43552).
651
656
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
658
658
if !name_binding. is_importable ( ) {
659
659
return ;
660
660
}
@@ -667,6 +667,17 @@ impl<'a> Resolver<'a> {
667
667
return ;
668
668
}
669
669
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
+
670
681
// collect results based on the filter function
671
682
// avoid suggesting anything from the same module in which we are resolving
672
683
if ident. name == lookup_ident. name
@@ -724,7 +735,8 @@ impl<'a> Resolver<'a> {
724
735
let is_extern = in_module_is_extern || name_binding. is_extern_crate ( ) ;
725
736
// add the module to the lookup
726
737
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) ) ;
728
740
}
729
741
}
730
742
}
0 commit comments