@@ -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,18 @@ 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+ warn_ambiguity,
92+ vis,
93+ span,
94+ expansion,
95+ } ) ;
8796 // Even if underscore names cannot be looked up, we still need to add them to modules,
8897 // because they can be fetched by glob imports from those modules, and bring traits
8998 // into scope both directly and through glob imports.
@@ -232,9 +241,22 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
232241 }
233242
234243 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)
244+ let def_id = module. def_id ( ) ;
245+ let children = self . tcx . module_children ( def_id) ;
246+ let parent_scope = ParentScope :: module ( module, self . arenas ) ;
247+ for ( i, child) in self . tcx . module_children ( def_id) . iter ( ) . enumerate ( ) {
248+ self . build_reduced_graph_for_external_crate_res ( child, parent_scope, i, None , false )
249+ }
250+ for ( i, child) in
251+ self . cstore ( ) . ambig_module_children_untracked ( def_id, self . tcx . sess ) . enumerate ( )
252+ {
253+ self . build_reduced_graph_for_external_crate_res (
254+ & child. main ,
255+ parent_scope,
256+ children. len ( ) + i,
257+ Some ( ( & child. second , child. kind ) ) ,
258+ child. warn_ambiguity ,
259+ )
238260 }
239261 }
240262
@@ -244,6 +266,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
244266 child : & ModChild ,
245267 parent_scope : ParentScope < ' ra > ,
246268 child_index : usize ,
269+ ambig_child : Option < ( & ModChild , AmbigModChildKind ) > ,
270+ warn_ambiguity : bool ,
247271 ) {
248272 let parent = parent_scope. module ;
249273 let ModChild { ident, res, vis, ref reexport_chain } = * child;
@@ -255,6 +279,21 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
255279 ) ;
256280 let res = res. expect_non_local ( ) ;
257281 let expansion = parent_scope. expansion ;
282+ let ambig = ambig_child. map ( |( ambig_child, ambig_kind) | {
283+ let ModChild { ident : _, res, vis, ref reexport_chain } = * ambig_child;
284+ let span = self . def_span (
285+ reexport_chain
286+ . first ( )
287+ . and_then ( |reexport| reexport. id ( ) )
288+ . unwrap_or_else ( || res. def_id ( ) ) ,
289+ ) ;
290+ let res = res. expect_non_local ( ) ;
291+ let ambig_kind = match ambig_kind {
292+ AmbigModChildKind :: GlobVsGlob => AmbiguityKind :: GlobVsGlob ,
293+ AmbigModChildKind :: GlobVsExpanded => AmbiguityKind :: GlobVsExpanded ,
294+ } ;
295+ ( self . arenas . new_res_binding ( res, vis, span, expansion) , ambig_kind)
296+ } ) ;
258297 // Record primary definitions.
259298 match res {
260299 Res :: Def (
@@ -272,9 +311,18 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
272311 _,
273312 )
274313 | Res :: PrimTy ( ..)
275- | Res :: ToolMod => {
276- self . define_extern ( parent, ident, TypeNS , child_index, res, vis, span, expansion)
277- }
314+ | Res :: ToolMod => self . define_extern (
315+ parent,
316+ ident,
317+ TypeNS ,
318+ child_index,
319+ res,
320+ vis,
321+ span,
322+ expansion,
323+ ambig,
324+ warn_ambiguity,
325+ ) ,
278326 Res :: Def (
279327 DefKind :: Fn
280328 | DefKind :: AssocFn
@@ -283,10 +331,30 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
283331 | DefKind :: AssocConst
284332 | DefKind :: Ctor ( ..) ,
285333 _,
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- }
334+ ) => self . define_extern (
335+ parent,
336+ ident,
337+ ValueNS ,
338+ child_index,
339+ res,
340+ vis,
341+ span,
342+ expansion,
343+ ambig,
344+ warn_ambiguity,
345+ ) ,
346+ Res :: Def ( DefKind :: Macro ( ..) , _) | Res :: NonMacroAttr ( ..) => self . define_extern (
347+ parent,
348+ ident,
349+ MacroNS ,
350+ child_index,
351+ res,
352+ vis,
353+ span,
354+ expansion,
355+ ambig,
356+ warn_ambiguity,
357+ ) ,
290358 Res :: Def (
291359 DefKind :: TyParam
292360 | DefKind :: ConstParam
0 commit comments