@@ -730,7 +730,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
730
730
let external_crate = if ns == TypeNS && self . extern_prelude . contains ( & name) {
731
731
let crate_id =
732
732
self . crate_loader . process_path_extern ( name, span) ;
733
- Some ( DefId { krate : crate_id, index : CRATE_DEF_INDEX } )
733
+ Some ( Def :: Mod ( DefId { krate : crate_id, index : CRATE_DEF_INDEX } ) )
734
734
} else {
735
735
None
736
736
} ;
@@ -741,30 +741,20 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
741
741
return ;
742
742
}
743
743
744
- let result_filter = |result : & & NameBinding | {
745
- // Ignore canaries that resolve to an import of the same crate.
746
- // That is, we allow `use crate_name; use crate_name::foo;`.
747
- if let Some ( def_id) = external_crate {
748
- if let Some ( module) = result. module ( ) {
749
- if module. normal_ancestor_id == def_id {
750
- return false ;
751
- }
752
- }
744
+ {
745
+ let mut all_results = external_crate. into_iter ( ) . chain (
746
+ results. module_scope . iter ( )
747
+ . chain ( & results. block_scopes )
748
+ . map ( |binding| binding. def ( ) )
749
+ ) ;
750
+ let first = all_results. next ( ) . unwrap ( ) ;
751
+
752
+ // An ambiguity requires more than one *distinct* possible resolution.
753
+ let possible_resultions =
754
+ 1 + all_results. filter ( |& def| def != first) . count ( ) ;
755
+ if possible_resultions <= 1 {
756
+ return ;
753
757
}
754
-
755
- true
756
- } ;
757
- let module_scope = results. module_scope . filter ( result_filter) ;
758
- let block_scopes = || {
759
- results. block_scopes . iter ( ) . cloned ( ) . filter ( result_filter)
760
- } ;
761
-
762
- // An ambiguity requires more than one possible resolution.
763
- let possible_resultions =
764
- ( external_crate. is_some ( ) as usize ) +
765
- module_scope. into_iter ( ) . chain ( block_scopes ( ) ) . count ( ) ;
766
- if possible_resultions <= 1 {
767
- return ;
768
758
}
769
759
770
760
errors = true ;
@@ -777,7 +767,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
777
767
err. span_label ( span,
778
768
format ! ( "can refer to external crate `::{}`" , name) ) ;
779
769
}
780
- if let Some ( result) = module_scope {
770
+ if let Some ( result) = results . module_scope {
781
771
if !suggestion_choices. is_empty ( ) {
782
772
suggestion_choices. push_str ( " or " ) ;
783
773
}
@@ -790,7 +780,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
790
780
format ! ( "may refer to `self::{}` in the future" , name) ) ;
791
781
}
792
782
}
793
- for result in block_scopes ( ) {
783
+ for result in results . block_scopes {
794
784
err. span_label ( result. span ,
795
785
format ! ( "shadowed by block-scoped `{}`" , name) ) ;
796
786
}
0 commit comments