11//! This module is used to store stuff from Rust's AST in a more convenient
22//! manner (and with prettier names) before cleaning.
3- use rustc_span:: { self , Span , Symbol } ;
4-
3+ use crate :: core:: DocContext ;
54use rustc_hir as hir;
5+ use rustc_span:: { self , Span , Symbol } ;
66
77/// A wrapper around a [`hir::Item`].
88#[ derive( Debug ) ]
@@ -11,8 +11,6 @@ crate struct Item<'hir> {
1111 crate hir_item : & ' hir hir:: Item < ' hir > ,
1212 /// the explicit renamed name
1313 crate renamed_name : Option < Symbol > ,
14- /// the [`Namespace`] this Item belongs to
15- crate namespace : Option < hir:: def:: Namespace > ,
1614 /// whether the item is from a glob import
1715 /// if `from_glob` is true and we see another item with same name and namespace,
1816 /// then this item can be replaced with that one
@@ -23,10 +21,9 @@ impl<'hir> Item<'hir> {
2321 pub ( crate ) fn new (
2422 hir_item : & ' hir hir:: Item < ' hir > ,
2523 renamed_name : Option < Symbol > ,
26- namespace : Option < hir:: def:: Namespace > ,
2724 from_glob : bool ,
2825 ) -> Self {
29- Self { hir_item, renamed_name, namespace , from_glob }
26+ Self { hir_item, renamed_name, from_glob }
3027 }
3128
3229 pub ( crate ) fn name ( & self ) -> Symbol {
@@ -66,13 +63,13 @@ impl Module<'hir> {
6663 }
6764 }
6865
69- pub ( crate ) fn push_item ( & mut self , new_item : Item < ' hir > ) {
70- if !new_item . name ( ) . is_empty ( ) && new_item. namespace . is_some ( ) {
71- if let Some ( existing_item ) = self
72- . items
73- . iter_mut ( )
74- . find ( |item| item . name ( ) == new_item . name ( ) && item. namespace == new_item . namespace )
75- {
66+ pub ( crate ) fn push_item ( & mut self , ctx : & DocContext < ' _ > , new_item : Item < ' hir > ) {
67+ let new_item_ns = ctx . tcx . def_kind ( new_item. hir_item . def_id ) . ns ( ) ;
68+ if !new_item . name ( ) . is_empty ( ) && new_item_ns . is_some ( ) {
69+ if let Some ( existing_item ) = self . items . iter_mut ( ) . find ( |item| {
70+ item . name ( ) == new_item . name ( )
71+ && ctx . tcx . def_kind ( item. hir_item . def_id ) . ns ( ) == new_item_ns
72+ } ) {
7673 match ( existing_item. from_glob , new_item. from_glob ) {
7774 ( true , _) => {
7875 // `existing_item` is from glob, no matter whether `new_item` is from glob,
0 commit comments