@@ -20,12 +20,6 @@ use crate::{
20
20
UseId ,
21
21
} ;
22
22
23
- #[ derive( Copy , Clone , Debug ) ]
24
- pub ( crate ) enum ImportType {
25
- Glob ,
26
- Named ,
27
- }
28
-
29
23
#[ derive( Debug , Default ) ]
30
24
pub struct PerNsGlobImports {
31
25
types : FxHashSet < ( LocalModuleId , Name ) > ,
@@ -35,6 +29,12 @@ pub struct PerNsGlobImports {
35
29
36
30
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
37
31
pub enum ImportOrExternCrate {
32
+ Import ( ImportId ) ,
33
+ ExternCrate ( ExternCrateId ) ,
34
+ }
35
+
36
+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
37
+ pub enum ImportType {
38
38
Import ( ImportId ) ,
39
39
Glob ( UseId ) ,
40
40
ExternCrate ( ExternCrateId ) ,
@@ -47,13 +47,6 @@ impl ImportOrExternCrate {
47
47
_ => None ,
48
48
}
49
49
}
50
-
51
- pub fn into_glob ( self ) -> Option < UseId > {
52
- match self {
53
- ImportOrExternCrate :: Glob ( it) => Some ( it) ,
54
- _ => None ,
55
- }
56
- }
57
50
}
58
51
59
52
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
@@ -89,9 +82,9 @@ pub struct ItemScope {
89
82
unnamed_trait_imports : FxHashMap < TraitId , ( Visibility , Option < ImportId > ) > ,
90
83
91
84
// the resolutions of the imports of this scope
92
- use_imports_types : FxHashMap < UseId , ImportOrDef > ,
93
- use_imports_values : FxHashMap < UseId , ImportOrDef > ,
94
- use_imports_macros : FxHashMap < UseId , ImportOrDef > ,
85
+ use_imports_types : FxHashMap < ImportOrExternCrate , ImportOrDef > ,
86
+ use_imports_values : FxHashMap < ImportId , ImportOrDef > ,
87
+ use_imports_macros : FxHashMap < ImportId , ImportOrDef > ,
95
88
96
89
use_decls : Vec < UseId > ,
97
90
extern_crate_decls : Vec < ExternCrateId > ,
@@ -347,51 +340,185 @@ impl ItemScope {
347
340
glob_imports : & mut PerNsGlobImports ,
348
341
lookup : ( LocalModuleId , Name ) ,
349
342
def : PerNs ,
350
- def_import_type : ImportType ,
343
+ import : Option < ImportType > ,
351
344
) -> bool {
352
345
let mut changed = false ;
353
346
354
- macro_rules! check_changed {
355
- (
356
- $changed: ident,
357
- ( $this: ident / $def: ident ) . $field: ident,
358
- $glob_imports: ident [ $lookup: ident ] ,
359
- $def_import_type: ident
360
- ) => { {
361
- if let Some ( fld) = $def. $field {
362
- let existing = $this. $field. entry( $lookup. 1 . clone( ) ) ;
363
- match existing {
364
- Entry :: Vacant ( entry) => {
365
- match $def_import_type {
366
- ImportType :: Glob => {
367
- $glob_imports. $field. insert( $lookup. clone( ) ) ;
347
+ if let Some ( mut fld) = def. types {
348
+ let existing = self . types . entry ( lookup. 1 . clone ( ) ) ;
349
+ match existing {
350
+ Entry :: Vacant ( entry) => {
351
+ match import {
352
+ Some ( ImportType :: Glob ( _) ) => {
353
+ glob_imports. types . insert ( lookup. clone ( ) ) ;
354
+ }
355
+ _ => _ = glob_imports. types . remove ( & lookup) ,
356
+ }
357
+ let import = match import {
358
+ Some ( ImportType :: ExternCrate ( extern_crate) ) => {
359
+ Some ( ImportOrExternCrate :: ExternCrate ( extern_crate) )
360
+ }
361
+ Some ( ImportType :: Import ( import) ) => {
362
+ Some ( ImportOrExternCrate :: Import ( import) )
363
+ }
364
+ None | Some ( ImportType :: Glob ( _) ) => None ,
365
+ } ;
366
+ let prev = std:: mem:: replace ( & mut fld. 2 , import) ;
367
+ if let Some ( ImportOrExternCrate :: Import ( import) ) = import {
368
+ self . use_imports_values . insert (
369
+ import,
370
+ match prev {
371
+ Some ( ImportOrExternCrate :: Import ( import) ) => {
372
+ ImportOrDef :: Import ( import)
368
373
}
369
- ImportType :: Named => {
370
- $glob_imports . $field . remove ( & $lookup ) ;
374
+ Some ( ImportOrExternCrate :: ExternCrate ( import ) ) => {
375
+ ImportOrDef :: ExternCrate ( import )
371
376
}
377
+ None => ImportOrDef :: Def ( fld. 0 ) ,
378
+ } ,
379
+ ) ;
380
+ }
381
+ entry. insert ( fld) ;
382
+ changed = true ;
383
+ }
384
+ Entry :: Occupied ( mut entry) if !matches ! ( import, Some ( ImportType :: Glob ( ..) ) ) => {
385
+ if glob_imports. types . remove ( & lookup) {
386
+ let import = match import {
387
+ Some ( ImportType :: ExternCrate ( extern_crate) ) => {
388
+ Some ( ImportOrExternCrate :: ExternCrate ( extern_crate) )
372
389
}
390
+ Some ( ImportType :: Import ( import) ) => {
391
+ Some ( ImportOrExternCrate :: Import ( import) )
392
+ }
393
+ None | Some ( ImportType :: Glob ( _) ) => None ,
394
+ } ;
395
+ let prev = std:: mem:: replace ( & mut fld. 2 , import) ;
396
+ if let Some ( ImportOrExternCrate :: Import ( import) ) = import {
397
+ self . use_imports_values . insert (
398
+ import,
399
+ match prev {
400
+ Some ( ImportOrExternCrate :: Import ( import) ) => {
401
+ ImportOrDef :: Import ( import)
402
+ }
403
+ Some ( ImportOrExternCrate :: ExternCrate ( import) ) => {
404
+ ImportOrDef :: ExternCrate ( import)
405
+ }
406
+ None => ImportOrDef :: Def ( fld. 0 ) ,
407
+ } ,
408
+ ) ;
409
+ }
410
+ cov_mark:: hit!( import_shadowed) ;
411
+ entry. insert ( fld) ;
412
+ changed = true ;
413
+ }
414
+ }
415
+ _ => { }
416
+ }
417
+ }
373
418
374
- entry. insert( fld) ;
375
- $changed = true ;
419
+ if let Some ( mut fld) = def. values {
420
+ let existing = self . values . entry ( lookup. 1 . clone ( ) ) ;
421
+ match existing {
422
+ Entry :: Vacant ( entry) => {
423
+ match import {
424
+ Some ( ImportType :: Glob ( _) ) => {
425
+ glob_imports. values . insert ( lookup. clone ( ) ) ;
376
426
}
377
- Entry :: Occupied ( mut entry)
378
- if matches!( $def_import_type, ImportType :: Named ) =>
379
- {
380
- if $glob_imports. $field. remove( & $lookup) {
381
- cov_mark:: hit!( import_shadowed) ;
382
- entry. insert( fld) ;
383
- $changed = true ;
384
- }
427
+ _ => _ = glob_imports. values . remove ( & lookup) ,
428
+ }
429
+ let import = match import {
430
+ Some ( ImportType :: Import ( import) ) => Some ( import) ,
431
+ _ => None ,
432
+ } ;
433
+ let prev = std:: mem:: replace ( & mut fld. 2 , import) ;
434
+ if let Some ( import) = import {
435
+ self . use_imports_values . insert (
436
+ import,
437
+ match prev {
438
+ Some ( import) => ImportOrDef :: Import ( import) ,
439
+ None => ImportOrDef :: Def ( fld. 0 ) ,
440
+ } ,
441
+ ) ;
442
+ }
443
+ entry. insert ( fld) ;
444
+ changed = true ;
445
+ }
446
+ Entry :: Occupied ( mut entry) if !matches ! ( import, Some ( ImportType :: Glob ( ..) ) ) => {
447
+ if glob_imports. values . remove ( & lookup) {
448
+ cov_mark:: hit!( import_shadowed) ;
449
+ let import = match import {
450
+ Some ( ImportType :: Import ( import) ) => Some ( import) ,
451
+ _ => None ,
452
+ } ;
453
+ let prev = std:: mem:: replace ( & mut fld. 2 , import) ;
454
+ if let Some ( import) = import {
455
+ self . use_imports_values . insert (
456
+ import,
457
+ match prev {
458
+ Some ( import) => ImportOrDef :: Import ( import) ,
459
+ None => ImportOrDef :: Def ( fld. 0 ) ,
460
+ } ,
461
+ ) ;
385
462
}
386
- _ => { }
463
+ entry. insert ( fld) ;
464
+ changed = true ;
387
465
}
388
466
}
389
- } } ;
467
+ _ => { }
468
+ }
390
469
}
391
470
392
- check_changed ! ( changed, ( self / def) . types, glob_imports[ lookup] , def_import_type) ;
393
- check_changed ! ( changed, ( self / def) . values, glob_imports[ lookup] , def_import_type) ;
394
- check_changed ! ( changed, ( self / def) . macros, glob_imports[ lookup] , def_import_type) ;
471
+ if let Some ( mut fld) = def. macros {
472
+ let existing = self . macros . entry ( lookup. 1 . clone ( ) ) ;
473
+ match existing {
474
+ Entry :: Vacant ( entry) => {
475
+ match import {
476
+ Some ( ImportType :: Glob ( _) ) => {
477
+ glob_imports. macros . insert ( lookup. clone ( ) ) ;
478
+ }
479
+ _ => _ = glob_imports. macros . remove ( & lookup) ,
480
+ }
481
+ let import = match import {
482
+ Some ( ImportType :: Import ( import) ) => Some ( import) ,
483
+ _ => None ,
484
+ } ;
485
+ let prev = std:: mem:: replace ( & mut fld. 2 , import) ;
486
+ if let Some ( import) = import {
487
+ self . use_imports_macros . insert (
488
+ import,
489
+ match prev {
490
+ Some ( import) => ImportOrDef :: Import ( import) ,
491
+ None => ImportOrDef :: Def ( fld. 0 . into ( ) ) ,
492
+ } ,
493
+ ) ;
494
+ }
495
+ entry. insert ( fld) ;
496
+ changed = true ;
497
+ }
498
+ Entry :: Occupied ( mut entry) if !matches ! ( import, Some ( ImportType :: Glob ( ..) ) ) => {
499
+ if glob_imports. macros . remove ( & lookup) {
500
+ cov_mark:: hit!( import_shadowed) ;
501
+ let import = match import {
502
+ Some ( ImportType :: Import ( import) ) => Some ( import) ,
503
+ _ => None ,
504
+ } ;
505
+ let prev = std:: mem:: replace ( & mut fld. 2 , import) ;
506
+ if let Some ( import) = import {
507
+ self . use_imports_macros . insert (
508
+ import,
509
+ match prev {
510
+ Some ( import) => ImportOrDef :: Import ( import) ,
511
+ None => ImportOrDef :: Def ( fld. 0 . into ( ) ) ,
512
+ } ,
513
+ ) ;
514
+ }
515
+ entry. insert ( fld) ;
516
+ changed = true ;
517
+ }
518
+ }
519
+ _ => { }
520
+ }
521
+ }
395
522
396
523
if def. is_none ( ) && self . unresolved . insert ( lookup. 1 ) {
397
524
changed = true ;
@@ -430,14 +557,25 @@ impl ItemScope {
430
557
name. map_or( "_" . to_string( ) , |name| name. display( db) . to_string( ) )
431
558
) ;
432
559
433
- if def . types . is_some ( ) {
560
+ if let Some ( ( .. , i ) ) = def . types {
434
561
buf. push_str ( " t" ) ;
562
+ match i {
563
+ Some ( ImportOrExternCrate :: Import ( _) ) => buf. push ( 'i' ) ,
564
+ Some ( ImportOrExternCrate :: ExternCrate ( _) ) => buf. push ( 'e' ) ,
565
+ None => ( ) ,
566
+ }
435
567
}
436
- if def . values . is_some ( ) {
568
+ if let Some ( ( .. , i ) ) = def . values {
437
569
buf. push_str ( " v" ) ;
570
+ if i. is_some ( ) {
571
+ buf. push ( 'i' ) ;
572
+ }
438
573
}
439
- if def . macros . is_some ( ) {
574
+ if let Some ( ( .. , i ) ) = def . macros {
440
575
buf. push_str ( " m" ) ;
576
+ if i. is_some ( ) {
577
+ buf. push ( 'i' ) ;
578
+ }
441
579
}
442
580
if def. is_none ( ) {
443
581
buf. push_str ( " _" ) ;
0 commit comments