@@ -9,7 +9,7 @@ use crate::def_collector::collect_definitions;
99use crate :: imports:: { ImportData , ImportKind } ;
1010use crate :: macros:: { MacroRulesBinding , MacroRulesScope , MacroRulesScopeRef } ;
1111use crate :: Namespace :: { self , MacroNS , TypeNS , ValueNS } ;
12- use crate :: { errors, BindingKey , MacroData , NameBindingData } ;
12+ use crate :: { errors, AmbiguityKind , BindingKey , MacroData , NameBindingData } ;
1313use crate :: { Determinacy , ExternPreludeEntry , Finalize , Module , ModuleKind , ModuleOrUniformRoot } ;
1414use crate :: { NameBinding , NameBindingKind , ParentScope , PathResult , PerNS , ResolutionError } ;
1515use crate :: { Resolver , ResolverArenas , Segment , ToNameBinding , VisResolutionError } ;
@@ -62,6 +62,46 @@ impl<'a, Id: Into<DefId>> ToNameBinding<'a> for (Res, ty::Visibility<Id>, Span,
6262 }
6363}
6464
65+ impl < ' a , Id : Into < DefId > > ToNameBinding < ' a >
66+ for ( Module < ' a > , ty:: Visibility < Id > , Span , LocalExpnId , bool )
67+ {
68+ fn to_name_binding ( self , arenas : & ' a ResolverArenas < ' a > ) -> NameBinding < ' a > {
69+ let mut binding = NameBindingData {
70+ kind : NameBindingKind :: Module ( self . 0 ) ,
71+ ambiguity : None ,
72+ warn_ambiguity : false ,
73+ vis : self . 1 . to_def_id ( ) ,
74+ span : self . 2 ,
75+ expansion : self . 3 ,
76+ } ;
77+ if self . 4 {
78+ binding. ambiguity =
79+ Some ( ( arenas. alloc_name_binding ( binding. clone ( ) ) , AmbiguityKind :: ExternalCrate ) ) ;
80+ binding. warn_ambiguity = true ;
81+ }
82+ arenas. alloc_name_binding ( binding)
83+ }
84+ }
85+
86+ impl < ' a , Id : Into < DefId > > ToNameBinding < ' a > for ( Res , ty:: Visibility < Id > , Span , LocalExpnId , bool ) {
87+ fn to_name_binding ( self , arenas : & ' a ResolverArenas < ' a > ) -> NameBinding < ' a > {
88+ let mut binding = NameBindingData {
89+ kind : NameBindingKind :: Res ( self . 0 ) ,
90+ ambiguity : None ,
91+ warn_ambiguity : false ,
92+ vis : self . 1 . to_def_id ( ) ,
93+ span : self . 2 ,
94+ expansion : self . 3 ,
95+ } ;
96+ if self . 4 {
97+ binding. ambiguity =
98+ Some ( ( arenas. alloc_name_binding ( binding. clone ( ) ) , AmbiguityKind :: ExternalCrate ) ) ;
99+ binding. warn_ambiguity = true ;
100+ }
101+ arenas. alloc_name_binding ( binding)
102+ }
103+ }
104+
65105impl < ' a , ' tcx > Resolver < ' a , ' tcx > {
66106 /// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
67107 /// otherwise, reports an error.
@@ -71,7 +111,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
71111 {
72112 let binding = def. to_name_binding ( self . arenas ) ;
73113 let key = self . new_disambiguated_key ( ident, ns) ;
74- if let Err ( old_binding) = self . try_define ( parent, key, binding, false ) {
114+ if let Err ( old_binding) = self . try_define ( parent, key, binding, binding . warn_ambiguity ) {
75115 self . report_conflict ( parent, ident, ns, old_binding, binding) ;
76116 }
77117 }
@@ -932,7 +972,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
932972 /// Builds the reduced graph for a single item in an external crate.
933973 fn build_reduced_graph_for_external_crate_res ( & mut self , child : & ModChild ) {
934974 let parent = self . parent_scope . module ;
935- let ModChild { ident, res, vis, ref reexport_chain } = * child;
975+ let ModChild { ident, res, vis, ref reexport_chain, ambiguity } = * child;
936976 let span = self . r . def_span (
937977 reexport_chain
938978 . first ( )
@@ -945,7 +985,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
945985 match res {
946986 Res :: Def ( DefKind :: Mod | DefKind :: Enum | DefKind :: Trait , def_id) => {
947987 let module = self . r . expect_module ( def_id) ;
948- self . r . define ( parent, ident, TypeNS , ( module, vis, span, expansion) ) ;
988+ self . r . define ( parent, ident, TypeNS , ( module, vis, span, expansion, ambiguity ) ) ;
949989 }
950990 Res :: Def (
951991 DefKind :: Struct
@@ -959,7 +999,9 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
959999 _,
9601000 )
9611001 | Res :: PrimTy ( ..)
962- | Res :: ToolMod => self . r . define ( parent, ident, TypeNS , ( res, vis, span, expansion) ) ,
1002+ | Res :: ToolMod => {
1003+ self . r . define ( parent, ident, TypeNS , ( res, vis, span, expansion, ambiguity) )
1004+ }
9631005 Res :: Def (
9641006 DefKind :: Fn
9651007 | DefKind :: AssocFn
@@ -968,9 +1010,9 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
9681010 | DefKind :: AssocConst
9691011 | DefKind :: Ctor ( ..) ,
9701012 _,
971- ) => self . r . define ( parent, ident, ValueNS , ( res, vis, span, expansion) ) ,
1013+ ) => self . r . define ( parent, ident, ValueNS , ( res, vis, span, expansion, ambiguity ) ) ,
9721014 Res :: Def ( DefKind :: Macro ( ..) , _) | Res :: NonMacroAttr ( ..) => {
973- self . r . define ( parent, ident, MacroNS , ( res, vis, span, expansion) )
1015+ self . r . define ( parent, ident, MacroNS , ( res, vis, span, expansion, ambiguity ) )
9741016 }
9751017 Res :: Def (
9761018 DefKind :: TyParam
0 commit comments