@@ -22,7 +22,7 @@ use rustc_hir::def::{self, *};
2222use  rustc_hir:: def_id:: { CRATE_DEF_ID ,  DefId ,  LocalDefId } ; 
2323use  rustc_index:: bit_set:: DenseBitSet ; 
2424use  rustc_metadata:: creader:: LoadedMacro ; 
25- use  rustc_middle:: metadata:: ModChild ; 
25+ use  rustc_middle:: metadata:: { AmbigModChildKind ,   ModChild } ; 
2626use  rustc_middle:: ty:: { Feed ,  Visibility } ; 
2727use  rustc_middle:: { bug,  span_bug} ; 
2828use  rustc_span:: hygiene:: { ExpnId ,  LocalExpnId ,  MacroKind } ; 
@@ -36,9 +36,9 @@ use crate::imports::{ImportData, ImportKind};
3636use  crate :: macros:: { MacroRulesBinding ,  MacroRulesScope ,  MacroRulesScopeRef } ; 
3737use  crate :: ref_mut:: CmCell ; 
3838use  crate :: { 
39-     BindingKey ,  ExternPreludeEntry ,  Finalize ,  MacroData ,  Module ,  ModuleKind ,   ModuleOrUniformRoot , 
40-     NameBinding ,   ParentScope ,   PathResult ,   ResolutionError ,   Resolver ,   Segment ,   Used , 
41-     VisResolutionError ,  errors, 
39+     AmbiguityKind ,   BindingKey ,  ExternPreludeEntry ,  Finalize ,  MacroData ,  Module ,  ModuleKind , 
40+     ModuleOrUniformRoot ,   NameBinding ,   NameBindingData ,   NameBindingKind ,   ParentScope ,   PathResult , 
41+     ResolutionError ,   Resolver ,   Segment ,   Used ,   VisResolutionError ,  errors, 
4242} ; 
4343
4444type  Res  = def:: Res < NodeId > ; 
@@ -81,9 +81,19 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
8181        res :  Res , 
8282        vis :  Visibility < DefId > , 
8383        span :  Span , 
84-         expn_id :  LocalExpnId , 
84+         expansion :  LocalExpnId , 
85+         ambiguity :  Option < ( NameBinding < ' ra > ,  AmbiguityKind ) > , 
86+         _warn_ambiguity :  bool , 
8587    )  { 
86-         let  binding = self . arenas . new_res_binding ( res,  vis,  span,  expn_id) ; 
88+         let  binding = self . arenas . alloc_name_binding ( NameBindingData  { 
89+             kind :  NameBindingKind :: Res ( res) , 
90+             ambiguity, 
91+             // FIXME: report everything as a lint for crater 
92+             warn_ambiguity :  true , 
93+             vis, 
94+             span, 
95+             expansion, 
96+         } ) ; 
8797        // Even if underscore names cannot be looked up, we still need to add them to modules, 
8898        // because they can be fetched by glob imports from those modules, and bring traits 
8999        // into scope both directly and through glob imports. 
@@ -232,9 +242,22 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
232242    } 
233243
234244    pub ( crate )  fn  build_reduced_graph_external ( & self ,  module :  Module < ' ra > )  { 
235-         for  ( i,  child)  in  self . tcx . module_children ( module. def_id ( ) ) . into_iter ( ) . enumerate ( )  { 
236-             let  parent_scope = ParentScope :: module ( module,  self . arenas ) ; 
237-             self . build_reduced_graph_for_external_crate_res ( child,  parent_scope,  i) 
245+         let  def_id = module. def_id ( ) ; 
246+         let  children = self . tcx . module_children ( def_id) ; 
247+         let  parent_scope = ParentScope :: module ( module,  self . arenas ) ; 
248+         for  ( i,  child)  in  self . tcx . module_children ( def_id) . iter ( ) . enumerate ( )  { 
249+             self . build_reduced_graph_for_external_crate_res ( child,  parent_scope,  i,  None ,  false ) 
250+         } 
251+         for  ( i,  child)  in 
252+             self . cstore ( ) . ambig_module_children_untracked ( def_id,  self . tcx . sess ) . enumerate ( ) 
253+         { 
254+             self . build_reduced_graph_for_external_crate_res ( 
255+                 & child. main , 
256+                 parent_scope, 
257+                 children. len ( )  + i, 
258+                 Some ( ( & child. second ,  child. kind ) ) , 
259+                 child. warn_ambiguity , 
260+             ) 
238261        } 
239262    } 
240263
@@ -244,6 +267,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
244267        child :  & ModChild , 
245268        parent_scope :  ParentScope < ' ra > , 
246269        child_index :  usize , 
270+         ambig_child :  Option < ( & ModChild ,  AmbigModChildKind ) > , 
271+         warn_ambiguity :  bool , 
247272    )  { 
248273        let  parent = parent_scope. module ; 
249274        let  ModChild  {  ident,  res,  vis,  ref  reexport_chain }  = * child; 
@@ -255,6 +280,21 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
255280        ) ; 
256281        let  res = res. expect_non_local ( ) ; 
257282        let  expansion = parent_scope. expansion ; 
283+         let  ambig = ambig_child. map ( |( ambig_child,  ambig_kind) | { 
284+             let  ModChild  {  ident :  _,  res,  vis,  ref  reexport_chain }  = * ambig_child; 
285+             let  span = self . def_span ( 
286+                 reexport_chain
287+                     . first ( ) 
288+                     . and_then ( |reexport| reexport. id ( ) ) 
289+                     . unwrap_or_else ( || res. def_id ( ) ) , 
290+             ) ; 
291+             let  res = res. expect_non_local ( ) ; 
292+             let  ambig_kind = match  ambig_kind { 
293+                 AmbigModChildKind :: GlobVsGlob  => AmbiguityKind :: GlobVsGlob , 
294+                 AmbigModChildKind :: GlobVsExpanded  => AmbiguityKind :: GlobVsExpanded , 
295+             } ; 
296+             ( self . arenas . new_res_binding ( res,  vis,  span,  expansion) ,  ambig_kind) 
297+         } ) ; 
258298        // Record primary definitions. 
259299        match  res { 
260300            Res :: Def ( 
@@ -272,9 +312,18 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
272312                _, 
273313            ) 
274314            | Res :: PrimTy ( ..) 
275-             | Res :: ToolMod  => { 
276-                 self . define_extern ( parent,  ident,  TypeNS ,  child_index,  res,  vis,  span,  expansion) 
277-             } 
315+             | Res :: ToolMod  => self . define_extern ( 
316+                 parent, 
317+                 ident, 
318+                 TypeNS , 
319+                 child_index, 
320+                 res, 
321+                 vis, 
322+                 span, 
323+                 expansion, 
324+                 ambig, 
325+                 warn_ambiguity, 
326+             ) , 
278327            Res :: Def ( 
279328                DefKind :: Fn 
280329                | DefKind :: AssocFn 
@@ -283,10 +332,30 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
283332                | DefKind :: AssocConst 
284333                | DefKind :: Ctor ( ..) , 
285334                _, 
286-             )  => self . define_extern ( parent,  ident,  ValueNS ,  child_index,  res,  vis,  span,  expansion) , 
287-             Res :: Def ( DefKind :: Macro ( ..) ,  _)  | Res :: NonMacroAttr ( ..)  => { 
288-                 self . define_extern ( parent,  ident,  MacroNS ,  child_index,  res,  vis,  span,  expansion) 
289-             } 
335+             )  => self . define_extern ( 
336+                 parent, 
337+                 ident, 
338+                 ValueNS , 
339+                 child_index, 
340+                 res, 
341+                 vis, 
342+                 span, 
343+                 expansion, 
344+                 ambig, 
345+                 warn_ambiguity, 
346+             ) , 
347+             Res :: Def ( DefKind :: Macro ( ..) ,  _)  | Res :: NonMacroAttr ( ..)  => self . define_extern ( 
348+                 parent, 
349+                 ident, 
350+                 MacroNS , 
351+                 child_index, 
352+                 res, 
353+                 vis, 
354+                 span, 
355+                 expansion, 
356+                 ambig, 
357+                 warn_ambiguity, 
358+             ) , 
290359            Res :: Def ( 
291360                DefKind :: TyParam 
292361                | DefKind :: ConstParam 
0 commit comments