@@ -24,7 +24,7 @@ use ParentLink::{ModuleParentLink, BlockParentLink};
24
24
use Resolver ;
25
25
use { resolve_error, resolve_struct_error, ResolutionError } ;
26
26
27
- use rustc:: middle:: cstore:: { CrateStore , ChildItem , DlDef , DlField , DlImpl } ;
27
+ use rustc:: middle:: cstore:: { CrateStore , ChildItem , DlDef } ;
28
28
use rustc:: middle:: def:: * ;
29
29
use rustc:: middle:: def_id:: { CRATE_DEF_INDEX , DefId } ;
30
30
use rustc:: middle:: ty:: VariantKind ;
@@ -42,7 +42,6 @@ use rustc_front::hir::{ItemForeignMod, ItemImpl, ItemMod, ItemStatic, ItemDefaul
42
42
use rustc_front:: hir:: { ItemStruct , ItemTrait , ItemTy , ItemUse } ;
43
43
use rustc_front:: hir:: { PathListIdent , PathListMod , StmtDecl } ;
44
44
use rustc_front:: hir:: { Variant , ViewPathGlob , ViewPathList , ViewPathSimple } ;
45
- use rustc_front:: hir:: Visibility ;
46
45
use rustc_front:: intravisit:: { self , Visitor } ;
47
46
48
47
use std:: mem:: replace;
@@ -439,42 +438,48 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
439
438
}
440
439
}
441
440
442
- fn handle_external_def ( & mut self ,
443
- def : Def ,
444
- vis : Visibility ,
445
- final_ident : & str ,
446
- name : Name ,
447
- new_parent : Module < ' b > ) {
448
- debug ! ( "(building reduced graph for external crate) building external def {}, priv {:?}" ,
449
- final_ident,
450
- vis) ;
451
- let is_public = vis == hir:: Public || new_parent. is_trait ( ) ;
441
+ /// Builds the reduced graph for a single item in an external crate.
442
+ fn build_reduced_graph_for_external_crate_def ( & mut self , parent : Module < ' b > , xcdef : ChildItem ) {
443
+ let def = match xcdef. def {
444
+ DlDef ( def) => def,
445
+ _ => return ,
446
+ } ;
447
+
448
+ if let Def :: ForeignMod ( def_id) = def {
449
+ // Foreign modules have no names. Recur and populate eagerly.
450
+ for child in self . session . cstore . item_children ( def_id) {
451
+ self . build_reduced_graph_for_external_crate_def ( parent, child) ;
452
+ }
453
+ return ;
454
+ }
455
+
456
+ let name = xcdef. name ;
457
+ let is_public = xcdef. vis == hir:: Public || parent. is_trait ( ) ;
452
458
453
459
let mut modifiers = DefModifiers :: empty ( ) ;
454
460
if is_public {
455
461
modifiers = modifiers | DefModifiers :: PUBLIC ;
456
462
}
457
- if new_parent . is_normal ( ) {
463
+ if parent . is_normal ( ) {
458
464
modifiers = modifiers | DefModifiers :: IMPORTABLE ;
459
465
}
460
466
461
467
match def {
462
468
Def :: Mod ( _) | Def :: ForeignMod ( _) | Def :: Enum ( ..) => {
463
469
debug ! ( "(building reduced graph for external crate) building module {} {}" ,
464
- final_ident ,
470
+ name ,
465
471
is_public) ;
466
- let parent_link = ModuleParentLink ( new_parent , name) ;
472
+ let parent_link = ModuleParentLink ( parent , name) ;
467
473
let module = self . new_module ( parent_link, Some ( def) , true , is_public) ;
468
- self . try_define ( new_parent , name, TypeNS , ( module, DUMMY_SP ) ) ;
474
+ self . try_define ( parent , name, TypeNS , ( module, DUMMY_SP ) ) ;
469
475
}
470
476
Def :: Variant ( _, variant_id) => {
471
- debug ! ( "(building reduced graph for external crate) building variant {}" ,
472
- final_ident) ;
477
+ debug ! ( "(building reduced graph for external crate) building variant {}" , name) ;
473
478
// Variants are always treated as importable to allow them to be glob used.
474
479
// All variants are defined in both type and value namespaces as future-proofing.
475
480
let modifiers = DefModifiers :: PUBLIC | DefModifiers :: IMPORTABLE ;
476
- self . try_define ( new_parent , name, TypeNS , ( def, DUMMY_SP , modifiers) ) ;
477
- self . try_define ( new_parent , name, ValueNS , ( def, DUMMY_SP , modifiers) ) ;
481
+ self . try_define ( parent , name, TypeNS , ( def, DUMMY_SP , modifiers) ) ;
482
+ self . try_define ( parent , name, ValueNS , ( def, DUMMY_SP , modifiers) ) ;
478
483
if self . session . cstore . variant_kind ( variant_id) == Some ( VariantKind :: Struct ) {
479
484
// Not adding fields for variants as they are not accessed with a self receiver
480
485
self . structs . insert ( variant_id, Vec :: new ( ) ) ;
@@ -486,12 +491,11 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
486
491
Def :: AssociatedConst ( ..) |
487
492
Def :: Method ( ..) => {
488
493
debug ! ( "(building reduced graph for external crate) building value (fn/static) {}" ,
489
- final_ident ) ;
490
- self . try_define ( new_parent , name, ValueNS , ( def, DUMMY_SP , modifiers) ) ;
494
+ name ) ;
495
+ self . try_define ( parent , name, ValueNS , ( def, DUMMY_SP , modifiers) ) ;
491
496
}
492
497
Def :: Trait ( def_id) => {
493
- debug ! ( "(building reduced graph for external crate) building type {}" ,
494
- final_ident) ;
498
+ debug ! ( "(building reduced graph for external crate) building type {}" , name) ;
495
499
496
500
// If this is a trait, add all the trait item names to the trait
497
501
// info.
@@ -508,24 +512,22 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
508
512
self . trait_item_map . insert ( ( trait_item_name, def_id) , trait_item_def. def_id ( ) ) ;
509
513
}
510
514
511
- let parent_link = ModuleParentLink ( new_parent , name) ;
515
+ let parent_link = ModuleParentLink ( parent , name) ;
512
516
let module = self . new_module ( parent_link, Some ( def) , true , is_public) ;
513
- self . try_define ( new_parent , name, TypeNS , ( module, DUMMY_SP ) ) ;
517
+ self . try_define ( parent , name, TypeNS , ( module, DUMMY_SP ) ) ;
514
518
}
515
519
Def :: TyAlias ( ..) | Def :: AssociatedTy ( ..) => {
516
- debug ! ( "(building reduced graph for external crate) building type {}" ,
517
- final_ident) ;
518
- self . try_define ( new_parent, name, TypeNS , ( def, DUMMY_SP , modifiers) ) ;
520
+ debug ! ( "(building reduced graph for external crate) building type {}" , name) ;
521
+ self . try_define ( parent, name, TypeNS , ( def, DUMMY_SP , modifiers) ) ;
519
522
}
520
523
Def :: Struct ( def_id)
521
524
if self . session . cstore . tuple_struct_definition_if_ctor ( def_id) . is_none ( ) => {
522
- debug ! ( "(building reduced graph for external crate) building type and value for \
523
- {}",
524
- final_ident) ;
525
- self . try_define ( new_parent, name, TypeNS , ( def, DUMMY_SP , modifiers) ) ;
525
+ debug ! ( "(building reduced graph for external crate) building type and value for {}" ,
526
+ name) ;
527
+ self . try_define ( parent, name, TypeNS , ( def, DUMMY_SP , modifiers) ) ;
526
528
if let Some ( ctor_def_id) = self . session . cstore . struct_ctor_def_id ( def_id) {
527
529
let def = Def :: Struct ( ctor_def_id) ;
528
- self . try_define ( new_parent , name, ValueNS , ( def, DUMMY_SP , modifiers) ) ;
530
+ self . try_define ( parent , name, ValueNS , ( def, DUMMY_SP , modifiers) ) ;
529
531
}
530
532
531
533
// Record the def ID and fields of this struct.
@@ -545,39 +547,6 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
545
547
}
546
548
}
547
549
548
- /// Builds the reduced graph for a single item in an external crate.
549
- fn build_reduced_graph_for_external_crate_def ( & mut self ,
550
- root : Module < ' b > ,
551
- xcdef : ChildItem ) {
552
- match xcdef. def {
553
- DlDef ( def) => {
554
- // Add the new child item, if necessary.
555
- match def {
556
- Def :: ForeignMod ( def_id) => {
557
- // Foreign modules have no names. Recur and populate
558
- // eagerly.
559
- for child in self . session . cstore . item_children ( def_id) {
560
- self . build_reduced_graph_for_external_crate_def ( root, child)
561
- }
562
- }
563
- _ => {
564
- self . handle_external_def ( def,
565
- xcdef. vis ,
566
- & xcdef. name . as_str ( ) ,
567
- xcdef. name ,
568
- root) ;
569
- }
570
- }
571
- }
572
- DlImpl ( _) => {
573
- debug ! ( "(building reduced graph for external crate) ignoring impl" ) ;
574
- }
575
- DlField => {
576
- debug ! ( "(building reduced graph for external crate) ignoring field" ) ;
577
- }
578
- }
579
- }
580
-
581
550
/// Builds the reduced graph rooted at the given external module.
582
551
fn populate_external_module ( & mut self , module : Module < ' b > ) {
583
552
debug ! ( "(populating external module) attempting to populate {}" ,
0 commit comments