@@ -136,12 +136,17 @@ impl ItemScope {
136
136
137
137
/// XXX: this is O(N) rather than O(1), try to not introduce new usages.
138
138
pub ( crate ) fn name_of ( & self , item : ItemInNs ) -> Option < ( & Name , Visibility ) > {
139
- for ( name, per_ns) in self . entries ( ) {
140
- if let Some ( vis) = item. match_with ( per_ns) {
141
- return Some ( ( name, vis) ) ;
139
+ let ( def, mut iter) = match item {
140
+ ItemInNs :: Macros ( def) => {
141
+ return self
142
+ . macros
143
+ . iter ( )
144
+ . find_map ( |( name, & ( other_def, vis) ) | ( other_def == def) . then ( || ( name, vis) ) ) ;
142
145
}
143
- }
144
- None
146
+ ItemInNs :: Types ( def) => ( def, self . types . iter ( ) ) ,
147
+ ItemInNs :: Values ( def) => ( def, self . values . iter ( ) ) ,
148
+ } ;
149
+ iter. find_map ( |( name, & ( other_def, vis) ) | ( other_def == def) . then ( || ( name, vis) ) )
145
150
}
146
151
147
152
pub ( crate ) fn traits < ' a > ( & ' a self ) -> impl Iterator < Item = TraitId > + ' a {
@@ -386,20 +391,6 @@ pub enum ItemInNs {
386
391
}
387
392
388
393
impl ItemInNs {
389
- fn match_with ( self , per_ns : PerNs ) -> Option < Visibility > {
390
- match self {
391
- ItemInNs :: Types ( def) => {
392
- per_ns. types . filter ( |( other_def, _) | * other_def == def) . map ( |( _, vis) | vis)
393
- }
394
- ItemInNs :: Values ( def) => {
395
- per_ns. values . filter ( |( other_def, _) | * other_def == def) . map ( |( _, vis) | vis)
396
- }
397
- ItemInNs :: Macros ( def) => {
398
- per_ns. macros . filter ( |( other_def, _) | * other_def == def) . map ( |( _, vis) | vis)
399
- }
400
- }
401
- }
402
-
403
394
pub fn as_module_def_id ( self ) -> Option < ModuleDefId > {
404
395
match self {
405
396
ItemInNs :: Types ( id) | ItemInNs :: Values ( id) => Some ( id) ,
0 commit comments