@@ -21,7 +21,8 @@ use rustc_middle::metadata::Reexport;
21
21
use rustc_middle:: span_bug;
22
22
use rustc_middle:: ty;
23
23
use rustc_session:: lint:: builtin:: {
24
- AMBIGUOUS_GLOB_REEXPORTS , PUB_USE_OF_PRIVATE_EXTERN_CRATE , UNUSED_IMPORTS ,
24
+ AMBIGUOUS_GLOB_REEXPORTS , HIDDEN_GLOB_REEXPORTS , PUB_USE_OF_PRIVATE_EXTERN_CRATE ,
25
+ UNUSED_IMPORTS ,
25
26
} ;
26
27
use rustc_session:: lint:: BuiltinLintDiagnostics ;
27
28
use rustc_span:: edit_distance:: find_best_match_for_name;
@@ -526,31 +527,71 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
526
527
}
527
528
}
528
529
529
- pub ( crate ) fn check_reexport_ambiguities (
530
+ pub ( crate ) fn check_hidden_glob_reexports (
530
531
& mut self ,
531
532
exported_ambiguities : FxHashSet < Interned < ' a , NameBinding < ' a > > > ,
532
533
) {
533
534
for module in self . arenas . local_modules ( ) . iter ( ) {
534
- module. for_each_child ( self , |this, ident, ns, binding| {
535
- if let NameBindingKind :: Import { import, .. } = binding. kind
536
- && let Some ( ( amb_binding, _) ) = binding. ambiguity
537
- && binding. res ( ) != Res :: Err
538
- && exported_ambiguities. contains ( & Interned :: new_unchecked ( binding) )
539
- {
540
- this. lint_buffer . buffer_lint_with_diagnostic (
541
- AMBIGUOUS_GLOB_REEXPORTS ,
542
- import. root_id ,
543
- import. root_span ,
544
- "ambiguous glob re-exports" ,
545
- BuiltinLintDiagnostics :: AmbiguousGlobReexports {
546
- name : ident. to_string ( ) ,
547
- namespace : ns. descr ( ) . to_string ( ) ,
548
- first_reexport_span : import. root_span ,
549
- duplicate_reexport_span : amb_binding. span ,
550
- } ,
551
- ) ;
535
+ for ( key, resolution) in self . resolutions ( module) . borrow ( ) . iter ( ) {
536
+ let resolution = resolution. borrow ( ) ;
537
+
538
+ if let Some ( binding) = resolution. binding {
539
+ if let NameBindingKind :: Import { import, .. } = binding. kind
540
+ && let Some ( ( amb_binding, _) ) = binding. ambiguity
541
+ && binding. res ( ) != Res :: Err
542
+ && exported_ambiguities. contains ( & Interned :: new_unchecked ( binding) )
543
+ {
544
+ self . lint_buffer . buffer_lint_with_diagnostic (
545
+ AMBIGUOUS_GLOB_REEXPORTS ,
546
+ import. root_id ,
547
+ import. root_span ,
548
+ "ambiguous glob re-exports" ,
549
+ BuiltinLintDiagnostics :: AmbiguousGlobReexports {
550
+ name : key. ident . to_string ( ) ,
551
+ namespace : key. ns . descr ( ) . to_string ( ) ,
552
+ first_reexport_span : import. root_span ,
553
+ duplicate_reexport_span : amb_binding. span ,
554
+ } ,
555
+ ) ;
556
+ }
557
+
558
+ if let Some ( glob_binding) = resolution. shadowed_glob {
559
+ let binding_id = match binding. kind {
560
+ NameBindingKind :: Res ( res) => {
561
+ Some ( self . def_id_to_node_id [ res. def_id ( ) . expect_local ( ) ] )
562
+ }
563
+ NameBindingKind :: Module ( module) => {
564
+ Some ( self . def_id_to_node_id [ module. def_id ( ) . expect_local ( ) ] )
565
+ }
566
+ NameBindingKind :: Import { import, .. } => import. id ( ) ,
567
+ } ;
568
+
569
+ if binding. res ( ) != Res :: Err
570
+ && glob_binding. res ( ) != Res :: Err
571
+ && let NameBindingKind :: Import { import : glob_import, .. } = glob_binding. kind
572
+ && let Some ( binding_id) = binding_id
573
+ && let Some ( glob_import_id) = glob_import. id ( )
574
+ && let glob_import_def_id = self . local_def_id ( glob_import_id)
575
+ && self . effective_visibilities . is_exported ( glob_import_def_id)
576
+ && glob_binding. vis . is_public ( )
577
+ && !binding. vis . is_public ( )
578
+ {
579
+ self . lint_buffer . buffer_lint_with_diagnostic (
580
+ HIDDEN_GLOB_REEXPORTS ,
581
+ binding_id,
582
+ binding. span ,
583
+ "private item shadows public glob re-export" ,
584
+ BuiltinLintDiagnostics :: HiddenGlobReexports {
585
+ name : key. ident . name . to_string ( ) ,
586
+ namespace : key. ns . descr ( ) . to_owned ( ) ,
587
+ glob_reexport_span : glob_binding. span ,
588
+ private_item_span : binding. span ,
589
+ } ,
590
+ ) ;
591
+ }
592
+ }
552
593
}
553
- } ) ;
594
+ }
554
595
}
555
596
}
556
597
0 commit comments