@@ -678,75 +678,13 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
678
678
}
679
679
680
680
ItemKind :: ExternCrate ( orig_name) => {
681
- let module = if orig_name. is_none ( ) && ident. name == kw:: SelfLower {
682
- self . r
683
- . session
684
- . struct_span_err ( item. span , "`extern crate self;` requires renaming" )
685
- . span_suggestion (
686
- item. span ,
687
- "try" ,
688
- "extern crate self as name;" . into ( ) ,
689
- Applicability :: HasPlaceholders ,
690
- )
691
- . emit ( ) ;
692
- return ;
693
- } else if orig_name == Some ( kw:: SelfLower ) {
694
- self . r . graph_root
695
- } else {
696
- let crate_id = self . r . crate_loader . process_extern_crate (
697
- item,
698
- & self . r . definitions ,
699
- local_def_id,
700
- ) ;
701
- self . r . extern_crate_map . insert ( local_def_id, crate_id) ;
702
- self . r . expect_module ( crate_id. as_def_id ( ) )
703
- } ;
704
-
705
- let used = self . process_macro_use_imports ( item, module) ;
706
- let binding =
707
- ( module, ty:: Visibility :: Public , sp, expansion) . to_name_binding ( self . r . arenas ) ;
708
- let import = self . r . arenas . alloc_import ( Import {
709
- kind : ImportKind :: ExternCrate { source : orig_name, target : ident } ,
710
- root_id : item. id ,
711
- id : item. id ,
712
- parent_scope : self . parent_scope ,
713
- imported_module : Cell :: new ( Some ( ModuleOrUniformRoot :: Module ( module) ) ) ,
714
- has_attributes : !item. attrs . is_empty ( ) ,
715
- use_span_with_attributes : item. span_with_attributes ( ) ,
716
- use_span : item. span ,
717
- root_span : item. span ,
718
- span : item. span ,
719
- module_path : Vec :: new ( ) ,
720
- vis : Cell :: new ( vis) ,
721
- used : Cell :: new ( used) ,
722
- } ) ;
723
- self . r . potentially_unused_imports . push ( import) ;
724
- let imported_binding = self . r . import ( binding, import) ;
725
- if ptr:: eq ( parent, self . r . graph_root ) {
726
- if let Some ( entry) = self . r . extern_prelude . get ( & ident. normalize_to_macros_2_0 ( ) )
727
- {
728
- if expansion != LocalExpnId :: ROOT
729
- && orig_name. is_some ( )
730
- && entry. extern_crate_item . is_none ( )
731
- {
732
- let msg = "macro-expanded `extern crate` items cannot \
733
- shadow names passed with `--extern`";
734
- self . r . session . span_err ( item. span , msg) ;
735
- }
736
- }
737
- let entry =
738
- self . r . extern_prelude . entry ( ident. normalize_to_macros_2_0 ( ) ) . or_insert (
739
- ExternPreludeEntry {
740
- extern_crate_item : None ,
741
- introduced_by_item : true ,
742
- } ,
743
- ) ;
744
- entry. extern_crate_item = Some ( imported_binding) ;
745
- if orig_name. is_some ( ) {
746
- entry. introduced_by_item = true ;
747
- }
748
- }
749
- self . r . define ( parent, ident, TypeNS , imported_binding) ;
681
+ self . build_reduced_graph_for_extern_crate (
682
+ orig_name,
683
+ item,
684
+ local_def_id,
685
+ vis,
686
+ parent,
687
+ ) ;
750
688
}
751
689
752
690
ItemKind :: Mod ( ..) => {
@@ -884,6 +822,87 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
884
822
}
885
823
}
886
824
825
+ fn build_reduced_graph_for_extern_crate (
826
+ & mut self ,
827
+ orig_name : Option < Symbol > ,
828
+ item : & Item ,
829
+ local_def_id : LocalDefId ,
830
+ vis : ty:: Visibility ,
831
+ parent : Module < ' a > ,
832
+ ) {
833
+ let ident = item. ident ;
834
+ let sp = item. span ;
835
+ let parent_scope = self . parent_scope ;
836
+ let expansion = parent_scope. expansion ;
837
+
838
+ let ( used, module, binding) = if orig_name. is_none ( ) && ident. name == kw:: SelfLower {
839
+ self . r
840
+ . session
841
+ . struct_span_err ( item. span , "`extern crate self;` requires renaming" )
842
+ . span_suggestion (
843
+ item. span ,
844
+ "rename the `self` crate to be able to import it" ,
845
+ "extern crate self as name;" . into ( ) ,
846
+ Applicability :: HasPlaceholders ,
847
+ )
848
+ . emit ( ) ;
849
+ return ;
850
+ } else if orig_name == Some ( kw:: SelfLower ) {
851
+ Some ( self . r . graph_root )
852
+ } else {
853
+ self . r . crate_loader . process_extern_crate ( item, & self . r . definitions , local_def_id) . map (
854
+ |crate_id| {
855
+ self . r . extern_crate_map . insert ( local_def_id, crate_id) ;
856
+ self . r . expect_module ( crate_id. as_def_id ( ) )
857
+ } ,
858
+ )
859
+ }
860
+ . map ( |module| {
861
+ let used = self . process_macro_use_imports ( item, module) ;
862
+ let binding =
863
+ ( module, ty:: Visibility :: Public , sp, expansion) . to_name_binding ( self . r . arenas ) ;
864
+ ( used, Some ( ModuleOrUniformRoot :: Module ( module) ) , binding)
865
+ } )
866
+ . unwrap_or ( ( true , None , self . r . dummy_binding ) ) ;
867
+ let import = self . r . arenas . alloc_import ( Import {
868
+ kind : ImportKind :: ExternCrate { source : orig_name, target : ident } ,
869
+ root_id : item. id ,
870
+ id : item. id ,
871
+ parent_scope : self . parent_scope ,
872
+ imported_module : Cell :: new ( module) ,
873
+ has_attributes : !item. attrs . is_empty ( ) ,
874
+ use_span_with_attributes : item. span_with_attributes ( ) ,
875
+ use_span : item. span ,
876
+ root_span : item. span ,
877
+ span : item. span ,
878
+ module_path : Vec :: new ( ) ,
879
+ vis : Cell :: new ( vis) ,
880
+ used : Cell :: new ( used) ,
881
+ } ) ;
882
+ self . r . potentially_unused_imports . push ( import) ;
883
+ let imported_binding = self . r . import ( binding, import) ;
884
+ if ptr:: eq ( parent, self . r . graph_root ) {
885
+ if let Some ( entry) = self . r . extern_prelude . get ( & ident. normalize_to_macros_2_0 ( ) ) {
886
+ if expansion != LocalExpnId :: ROOT
887
+ && orig_name. is_some ( )
888
+ && entry. extern_crate_item . is_none ( )
889
+ {
890
+ let msg = "macro-expanded `extern crate` items cannot \
891
+ shadow names passed with `--extern`";
892
+ self . r . session . span_err ( item. span , msg) ;
893
+ }
894
+ }
895
+ let entry = self . r . extern_prelude . entry ( ident. normalize_to_macros_2_0 ( ) ) . or_insert (
896
+ ExternPreludeEntry { extern_crate_item : None , introduced_by_item : true } ,
897
+ ) ;
898
+ entry. extern_crate_item = Some ( imported_binding) ;
899
+ if orig_name. is_some ( ) {
900
+ entry. introduced_by_item = true ;
901
+ }
902
+ }
903
+ self . r . define ( parent, ident, TypeNS , imported_binding) ;
904
+ }
905
+
887
906
/// Constructs the reduced graph for one foreign item.
888
907
fn build_reduced_graph_for_foreign_item ( & mut self , item : & ForeignItem ) {
889
908
let local_def_id = self . r . local_def_id ( item. id ) ;
0 commit comments