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