6
6
//! Imports are also considered items and placed into modules here, but not resolved yet.
7
7
8
8
use crate :: def_collector:: collect_definitions;
9
- use crate :: imports:: ImportDirective ;
10
- use crate :: imports:: ImportDirectiveSubclass :: { self , GlobImport , SingleImport } ;
9
+ use crate :: imports:: { Import , ImportKind } ;
11
10
use crate :: macros:: { LegacyBinding , LegacyScope } ;
12
11
use crate :: Namespace :: { self , MacroNS , TypeNS , ValueNS } ;
13
12
use crate :: { CrateLint , Determinacy , PathResult , ResolutionError , VisResolutionError } ;
@@ -308,11 +307,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
308
307
} )
309
308
}
310
309
311
- // Add an import directive to the current module.
312
- fn add_import_directive (
310
+ // Add an import to the current module.
311
+ fn add_import (
313
312
& mut self ,
314
313
module_path : Vec < Segment > ,
315
- subclass : ImportDirectiveSubclass < ' a > ,
314
+ kind : ImportKind < ' a > ,
316
315
span : Span ,
317
316
id : NodeId ,
318
317
item : & ast:: Item ,
@@ -321,11 +320,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
321
320
vis : ty:: Visibility ,
322
321
) {
323
322
let current_module = self . parent_scope . module ;
324
- let directive = self . r . arenas . alloc_import_directive ( ImportDirective {
323
+ let import = self . r . arenas . alloc_import ( Import {
324
+ kind,
325
325
parent_scope : self . parent_scope ,
326
326
module_path,
327
327
imported_module : Cell :: new ( None ) ,
328
- subclass,
329
328
span,
330
329
id,
331
330
use_span : item. span ,
@@ -337,25 +336,25 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
337
336
used : Cell :: new ( false ) ,
338
337
} ) ;
339
338
340
- debug ! ( "add_import_directive ({:?})" , directive ) ;
339
+ debug ! ( "add_import ({:?})" , import ) ;
341
340
342
- self . r . indeterminate_imports . push ( directive ) ;
343
- match directive . subclass {
341
+ self . r . indeterminate_imports . push ( import ) ;
342
+ match import . kind {
344
343
// Don't add unresolved underscore imports to modules
345
- SingleImport { target : Ident { name : kw:: Underscore , .. } , .. } => { }
346
- SingleImport { target, type_ns_only, .. } => {
344
+ ImportKind :: Single { target : Ident { name : kw:: Underscore , .. } , .. } => { }
345
+ ImportKind :: Single { target, type_ns_only, .. } => {
347
346
self . r . per_ns ( |this, ns| {
348
347
if !type_ns_only || ns == TypeNS {
349
348
let key = this. new_key ( target, ns) ;
350
349
let mut resolution = this. resolution ( current_module, key) . borrow_mut ( ) ;
351
- resolution. add_single_import ( directive ) ;
350
+ resolution. add_single_import ( import ) ;
352
351
}
353
352
} ) ;
354
353
}
355
354
// We don't add prelude imports to the globs since they only affect lexical scopes,
356
355
// which are not relevant to import resolution.
357
- GlobImport { is_prelude : true , .. } => { }
358
- GlobImport { .. } => current_module. globs . borrow_mut ( ) . push ( directive ) ,
356
+ ImportKind :: Glob { is_prelude : true , .. } => { }
357
+ ImportKind :: Glob { .. } => current_module. globs . borrow_mut ( ) . push ( import ) ,
359
358
_ => unreachable ! ( ) ,
360
359
}
361
360
}
@@ -480,7 +479,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
480
479
) ;
481
480
}
482
481
483
- let subclass = SingleImport {
482
+ let kind = ImportKind :: Single {
484
483
source : source. ident ,
485
484
target : ident,
486
485
source_bindings : PerNS {
@@ -496,9 +495,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
496
495
type_ns_only,
497
496
nested,
498
497
} ;
499
- self . add_import_directive (
498
+ self . add_import (
500
499
module_path,
501
- subclass ,
500
+ kind ,
502
501
use_tree. span ,
503
502
id,
504
503
item,
@@ -508,20 +507,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
508
507
) ;
509
508
}
510
509
ast:: UseTreeKind :: Glob => {
511
- let subclass = GlobImport {
510
+ let kind = ImportKind :: Glob {
512
511
is_prelude : attr:: contains_name ( & item. attrs , sym:: prelude_import) ,
513
512
max_vis : Cell :: new ( ty:: Visibility :: Invisible ) ,
514
513
} ;
515
- self . add_import_directive (
516
- prefix,
517
- subclass,
518
- use_tree. span ,
519
- id,
520
- item,
521
- root_span,
522
- item. id ,
523
- vis,
524
- ) ;
514
+ self . add_import ( prefix, kind, use_tree. span , id, item, root_span, item. id , vis) ;
525
515
}
526
516
ast:: UseTreeKind :: Nested ( ref items) => {
527
517
// Ensure there is at most one `self` in the list
@@ -637,15 +627,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
637
627
let used = self . process_legacy_macro_imports ( item, module) ;
638
628
let binding =
639
629
( module, ty:: Visibility :: Public , sp, expansion) . to_name_binding ( self . r . arenas ) ;
640
- let directive = self . r . arenas . alloc_import_directive ( ImportDirective {
630
+ let import = self . r . arenas . alloc_import ( Import {
631
+ kind : ImportKind :: ExternCrate { source : orig_name, target : ident } ,
641
632
root_id : item. id ,
642
633
id : item. id ,
643
634
parent_scope : self . parent_scope ,
644
635
imported_module : Cell :: new ( Some ( ModuleOrUniformRoot :: Module ( module) ) ) ,
645
- subclass : ImportDirectiveSubclass :: ExternCrate {
646
- source : orig_name,
647
- target : ident,
648
- } ,
649
636
has_attributes : !item. attrs . is_empty ( ) ,
650
637
use_span_with_attributes : item. span_with_attributes ( ) ,
651
638
use_span : item. span ,
@@ -655,8 +642,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
655
642
vis : Cell :: new ( vis) ,
656
643
used : Cell :: new ( used) ,
657
644
} ) ;
658
- self . r . potentially_unused_imports . push ( directive ) ;
659
- let imported_binding = self . r . import ( binding, directive ) ;
645
+ self . r . potentially_unused_imports . push ( import ) ;
646
+ let imported_binding = self . r . import ( binding, import ) ;
660
647
if ptr:: eq ( parent, self . r . graph_root ) {
661
648
if let Some ( entry) = self . r . extern_prelude . get ( & ident. modern ( ) ) {
662
649
if expansion != ExpnId :: root ( )
@@ -992,13 +979,13 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
992
979
}
993
980
}
994
981
995
- let macro_use_directive = |this : & Self , span| {
996
- this. r . arenas . alloc_import_directive ( ImportDirective {
982
+ let macro_use_import = |this : & Self , span| {
983
+ this. r . arenas . alloc_import ( Import {
984
+ kind : ImportKind :: MacroUse ,
997
985
root_id : item. id ,
998
986
id : item. id ,
999
987
parent_scope : this. parent_scope ,
1000
988
imported_module : Cell :: new ( Some ( ModuleOrUniformRoot :: Module ( module) ) ) ,
1001
- subclass : ImportDirectiveSubclass :: MacroUse ,
1002
989
use_span_with_attributes : item. span_with_attributes ( ) ,
1003
990
has_attributes : !item. attrs . is_empty ( ) ,
1004
991
use_span : item. span ,
@@ -1012,11 +999,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
1012
999
1013
1000
let allow_shadowing = self . parent_scope . expansion == ExpnId :: root ( ) ;
1014
1001
if let Some ( span) = import_all {
1015
- let directive = macro_use_directive ( self , span) ;
1016
- self . r . potentially_unused_imports . push ( directive ) ;
1002
+ let import = macro_use_import ( self , span) ;
1003
+ self . r . potentially_unused_imports . push ( import ) ;
1017
1004
module. for_each_child ( self , |this, ident, ns, binding| {
1018
1005
if ns == MacroNS {
1019
- let imported_binding = this. r . import ( binding, directive ) ;
1006
+ let imported_binding = this. r . import ( binding, import ) ;
1020
1007
this. legacy_import_macro ( ident. name , imported_binding, span, allow_shadowing) ;
1021
1008
}
1022
1009
} ) ;
@@ -1031,9 +1018,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
1031
1018
ident. span ,
1032
1019
) ;
1033
1020
if let Ok ( binding) = result {
1034
- let directive = macro_use_directive ( self , ident. span ) ;
1035
- self . r . potentially_unused_imports . push ( directive ) ;
1036
- let imported_binding = self . r . import ( binding, directive ) ;
1021
+ let import = macro_use_import ( self , ident. span ) ;
1022
+ self . r . potentially_unused_imports . push ( import ) ;
1023
+ let imported_binding = self . r . import ( binding, import ) ;
1037
1024
self . legacy_import_macro (
1038
1025
ident. name ,
1039
1026
imported_binding,
0 commit comments