@@ -9,7 +9,7 @@ use rustc_ast as ast;
9
9
use rustc_data_structures:: fx:: FxHashSet ;
10
10
use rustc_hir as hir;
11
11
use rustc_hir:: def:: { DefKind , Res } ;
12
- use rustc_hir:: def_id:: DefId ;
12
+ use rustc_hir:: def_id:: { DefId , LocalDefId } ;
13
13
use rustc_hir:: Mutability ;
14
14
use rustc_metadata:: creader:: { CStore , LoadedMacro } ;
15
15
use rustc_middle:: ty:: { self , TyCtxt } ;
@@ -162,6 +162,7 @@ pub(crate) fn try_inline(
162
162
pub ( crate ) fn try_inline_glob (
163
163
cx : & mut DocContext < ' _ > ,
164
164
res : Res ,
165
+ current_mod : LocalDefId ,
165
166
visited : & mut FxHashSet < DefId > ,
166
167
inlined_names : & mut FxHashSet < ( ItemType , Symbol ) > ,
167
168
) -> Option < Vec < clean:: Item > > {
@@ -172,7 +173,16 @@ pub(crate) fn try_inline_glob(
172
173
173
174
match res {
174
175
Res :: Def ( DefKind :: Mod , did) => {
175
- let mut items = build_module_items ( cx, did, visited, inlined_names) ;
176
+ // Use the set of module reexports to filter away names that are not actually
177
+ // reexported by the glob, e.g. because they are shadowed by something else.
178
+ let reexports = cx
179
+ . tcx
180
+ . module_reexports ( current_mod)
181
+ . unwrap_or_default ( )
182
+ . iter ( )
183
+ . filter_map ( |child| child. res . opt_def_id ( ) )
184
+ . collect ( ) ;
185
+ let mut items = build_module_items ( cx, did, visited, inlined_names, Some ( & reexports) ) ;
176
186
items. drain_filter ( |item| {
177
187
if let Some ( name) = item. name {
178
188
// If an item with the same type and name already exists,
@@ -563,7 +573,7 @@ fn build_module(
563
573
did : DefId ,
564
574
visited : & mut FxHashSet < DefId > ,
565
575
) -> clean:: Module {
566
- let items = build_module_items ( cx, did, visited, & mut FxHashSet :: default ( ) ) ;
576
+ let items = build_module_items ( cx, did, visited, & mut FxHashSet :: default ( ) , None ) ;
567
577
568
578
let span = clean:: Span :: new ( cx. tcx . def_span ( did) ) ;
569
579
clean:: Module { items, span }
@@ -574,6 +584,7 @@ fn build_module_items(
574
584
did : DefId ,
575
585
visited : & mut FxHashSet < DefId > ,
576
586
inlined_names : & mut FxHashSet < ( ItemType , Symbol ) > ,
587
+ allowed_def_ids : Option < & FxHashSet < DefId > > ,
577
588
) -> Vec < clean:: Item > {
578
589
let mut items = Vec :: new ( ) ;
579
590
@@ -583,6 +594,11 @@ fn build_module_items(
583
594
for & item in cx. tcx . module_children ( did) . iter ( ) {
584
595
if item. vis . is_public ( ) {
585
596
let res = item. res . expect_non_local ( ) ;
597
+ if let Some ( def_id) = res. opt_def_id ( )
598
+ && let Some ( allowed_def_ids) = allowed_def_ids
599
+ && !allowed_def_ids. contains ( & def_id) {
600
+ continue ;
601
+ }
586
602
if let Some ( def_id) = res. mod_def_id ( ) {
587
603
// If we're inlining a glob import, it's possible to have
588
604
// two distinct modules with the same name. We don't want to
0 commit comments