1
1
//! This module is used to store stuff from Rust's AST in a more convenient
2
2
//! manner (and with prettier names) before cleaning.
3
- use rustc_span:: { self , Span , Symbol } ;
4
-
3
+ use crate :: core:: DocContext ;
5
4
use rustc_hir as hir;
5
+ use rustc_span:: { self , Span , Symbol } ;
6
6
7
7
/// A wrapper around a [`hir::Item`].
8
8
#[ derive( Debug ) ]
@@ -11,8 +11,6 @@ crate struct Item<'hir> {
11
11
crate hir_item : & ' hir hir:: Item < ' hir > ,
12
12
/// the explicit renamed name
13
13
crate renamed_name : Option < Symbol > ,
14
- /// the [`Namespace`] this Item belongs to
15
- crate namespace : Option < hir:: def:: Namespace > ,
16
14
/// whether the item is from a glob import
17
15
/// if `from_glob` is true and we see another item with same name and namespace,
18
16
/// then this item can be replaced with that one
@@ -23,10 +21,9 @@ impl<'hir> Item<'hir> {
23
21
pub ( crate ) fn new (
24
22
hir_item : & ' hir hir:: Item < ' hir > ,
25
23
renamed_name : Option < Symbol > ,
26
- namespace : Option < hir:: def:: Namespace > ,
27
24
from_glob : bool ,
28
25
) -> Self {
29
- Self { hir_item, renamed_name, namespace , from_glob }
26
+ Self { hir_item, renamed_name, from_glob }
30
27
}
31
28
32
29
pub ( crate ) fn name ( & self ) -> Symbol {
@@ -66,13 +63,13 @@ impl Module<'hir> {
66
63
}
67
64
}
68
65
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
+ } ) {
76
73
match ( existing_item. from_glob , new_item. from_glob ) {
77
74
( true , _) => {
78
75
// `existing_item` is from glob, no matter whether `new_item` is from glob,
0 commit comments