@@ -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 , Reexport } ;
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 ) > ,
8586 ) {
86- let binding = self . arenas . new_res_binding ( res, vis, span, expn_id) ;
87+ let binding = self . arenas . alloc_name_binding ( NameBindingData {
88+ kind : NameBindingKind :: Res ( res) ,
89+ ambiguity,
90+ // External ambiguities always report the `AMBIGUOUS_GLOB_IMPORTS` lint at the moment.
91+ warn_ambiguity : true ,
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,21 @@ 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 children. iter ( ) . enumerate ( ) {
248+ self . build_reduced_graph_for_external_crate_res ( child, parent_scope, i, None )
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+ )
238259 }
239260 }
240261
@@ -244,17 +265,31 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
244265 child : & ModChild ,
245266 parent_scope : ParentScope < ' ra > ,
246267 child_index : usize ,
268+ ambig_child : Option < ( & ModChild , AmbigModChildKind ) > ,
247269 ) {
248270 let parent = parent_scope. module ;
271+ let child_span = |this : & Self , reexport_chain : & [ Reexport ] , res : def:: Res < _ > | {
272+ this. def_span (
273+ reexport_chain
274+ . first ( )
275+ . and_then ( |reexport| reexport. id ( ) )
276+ . unwrap_or_else ( || res. def_id ( ) ) ,
277+ )
278+ } ;
249279 let ModChild { ident, res, vis, ref reexport_chain } = * child;
250- let span = self . def_span (
251- reexport_chain
252- . first ( )
253- . and_then ( |reexport| reexport. id ( ) )
254- . unwrap_or_else ( || res. def_id ( ) ) ,
255- ) ;
280+ let span = child_span ( self , reexport_chain, res) ;
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 = child_span ( self , reexport_chain, res) ;
286+ let res = res. expect_non_local ( ) ;
287+ let ambig_kind = match ambig_kind {
288+ AmbigModChildKind :: GlobVsGlob => AmbiguityKind :: GlobVsGlob ,
289+ AmbigModChildKind :: GlobVsExpanded => AmbiguityKind :: GlobVsExpanded ,
290+ } ;
291+ ( self . arenas . new_res_binding ( res, vis, span, expansion) , ambig_kind)
292+ } ) ;
258293 // Record primary definitions.
259294 match res {
260295 Res :: Def (
@@ -272,9 +307,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
272307 _,
273308 )
274309 | Res :: PrimTy ( ..)
275- | Res :: ToolMod => {
276- self . define_extern ( parent, ident, TypeNS , child_index, res, vis, span, expansion)
277- }
310+ | Res :: ToolMod => self . define_extern (
311+ parent,
312+ ident,
313+ TypeNS ,
314+ child_index,
315+ res,
316+ vis,
317+ span,
318+ expansion,
319+ ambig,
320+ ) ,
278321 Res :: Def (
279322 DefKind :: Fn
280323 | DefKind :: AssocFn
@@ -283,10 +326,28 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
283326 | DefKind :: AssocConst
284327 | DefKind :: Ctor ( ..) ,
285328 _,
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- }
329+ ) => self . define_extern (
330+ parent,
331+ ident,
332+ ValueNS ,
333+ child_index,
334+ res,
335+ vis,
336+ span,
337+ expansion,
338+ ambig,
339+ ) ,
340+ Res :: Def ( DefKind :: Macro ( ..) , _) | Res :: NonMacroAttr ( ..) => self . define_extern (
341+ parent,
342+ ident,
343+ MacroNS ,
344+ child_index,
345+ res,
346+ vis,
347+ span,
348+ expansion,
349+ ambig,
350+ ) ,
290351 Res :: Def (
291352 DefKind :: TyParam
292353 | DefKind :: ConstParam
0 commit comments