@@ -818,6 +818,8 @@ pub struct ModuleS<'a> {
818
818
// entry block for `f`.
819
819
anonymous_children : RefCell < NodeMap < Module < ' a > > > ,
820
820
821
+ shadowed_traits : RefCell < Vec < & ' a NameBinding < ' a > > > ,
822
+
821
823
// The number of unresolved globs that this module exports.
822
824
glob_count : Cell < usize > ,
823
825
@@ -848,6 +850,7 @@ impl<'a> ModuleS<'a> {
848
850
children : RefCell :: new ( HashMap :: new ( ) ) ,
849
851
imports : RefCell :: new ( Vec :: new ( ) ) ,
850
852
anonymous_children : RefCell :: new ( NodeMap ( ) ) ,
853
+ shadowed_traits : RefCell :: new ( Vec :: new ( ) ) ,
851
854
glob_count : Cell :: new ( 0 ) ,
852
855
pub_count : Cell :: new ( 0 ) ,
853
856
pub_glob_count : Cell :: new ( 0 ) ,
@@ -871,8 +874,19 @@ impl<'a> ModuleS<'a> {
871
874
// Define the name or return the existing binding if there is a collision.
872
875
fn try_define_child ( & self , name : Name , ns : Namespace , binding : & ' a NameBinding < ' a > )
873
876
-> Result < ( ) , & ' a NameBinding < ' a > > {
874
- self . children . borrow_mut ( ) . entry ( ( name, ns) ) . or_insert_with ( Default :: default)
875
- . try_define ( binding)
877
+ let mut children = self . children . borrow_mut ( ) ;
878
+ let resolution = children. entry ( ( name, ns) ) . or_insert_with ( Default :: default) ;
879
+
880
+ // FIXME #31379: We can use methods from imported traits shadowed by non-import items
881
+ if let Some ( old_binding) = resolution. binding {
882
+ if !old_binding. is_import ( ) && binding. is_import ( ) {
883
+ if let Some ( Def :: Trait ( _) ) = binding. def ( ) {
884
+ self . shadowed_traits . borrow_mut ( ) . push ( binding) ;
885
+ }
886
+ }
887
+ }
888
+
889
+ resolution. try_define ( binding)
876
890
}
877
891
878
892
fn increment_outstanding_references_for ( & self , name : Name , ns : Namespace ) {
@@ -3466,6 +3480,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3466
3480
}
3467
3481
} ) ;
3468
3482
3483
+ // Look for shadowed traits.
3484
+ for binding in search_module. shadowed_traits . borrow ( ) . iter ( ) {
3485
+ let did = binding. def ( ) . unwrap ( ) . def_id ( ) ;
3486
+ if self . trait_item_map . contains_key ( & ( name, did) ) {
3487
+ add_trait_info ( & mut found_traits, did, name) ;
3488
+ let trait_name = self . get_trait_name ( did) ;
3489
+ self . record_use ( trait_name, TypeNS , binding) ;
3490
+ }
3491
+ }
3492
+
3469
3493
match search_module. parent_link {
3470
3494
NoParentLink | ModuleParentLink ( ..) => break ,
3471
3495
BlockParentLink ( parent_module, _) => {
0 commit comments