@@ -76,7 +76,7 @@ use std::fmt;
7676use std:: mem:: replace;
7777use std:: rc:: Rc ;
7878
79- use resolve_imports:: { ImportDirective , NameResolution } ;
79+ use resolve_imports:: { ImportDirective , ImportDirectiveSubclass , NameResolution } ;
8080use macros:: { InvocationData , LegacyBinding , LegacyScope } ;
8181
8282// NB: This module needs to be declared first so diagnostics are
@@ -796,10 +796,6 @@ pub struct ModuleS<'a> {
796796 // The node id of the closest normal module (`mod`) ancestor (including this module).
797797 normal_ancestor_id : Option < NodeId > ,
798798
799- // If the module is an extern crate, `def` is root of the external crate and `extern_crate_id`
800- // is the NodeId of the local `extern crate` item (otherwise, `extern_crate_id` is None).
801- extern_crate_id : Option < NodeId > ,
802-
803799 resolutions : RefCell < FxHashMap < ( Name , Namespace ) , & ' a RefCell < NameResolution < ' a > > > > ,
804800
805801 no_implicit_prelude : bool ,
@@ -824,7 +820,6 @@ impl<'a> ModuleS<'a> {
824820 parent : parent,
825821 kind : kind,
826822 normal_ancestor_id : None ,
827- extern_crate_id : None ,
828823 resolutions : RefCell :: new ( FxHashMap ( ) ) ,
829824 no_implicit_prelude : false ,
830825 glob_importers : RefCell :: new ( Vec :: new ( ) ) ,
@@ -953,7 +948,14 @@ impl<'a> NameBinding<'a> {
953948 }
954949
955950 fn is_extern_crate ( & self ) -> bool {
956- self . module ( ) . ok ( ) . and_then ( |module| module. extern_crate_id ) . is_some ( )
951+ match self . kind {
952+ NameBindingKind :: Import {
953+ directive : & ImportDirective {
954+ subclass : ImportDirectiveSubclass :: ExternCrate , ..
955+ } , ..
956+ } => true ,
957+ _ => false ,
958+ }
957959 }
958960
959961 fn is_import ( & self ) -> bool {
@@ -3233,7 +3235,7 @@ impl<'a> Resolver<'a> {
32333235 in_module. for_each_child ( |name, ns, name_binding| {
32343236
32353237 // avoid imports entirely
3236- if name_binding. is_import ( ) { return ; }
3238+ if name_binding. is_import ( ) && !name_binding . is_extern_crate ( ) { return ; }
32373239
32383240 // collect results based on the filter function
32393241 if name == lookup_name && ns == namespace {
@@ -3269,21 +3271,11 @@ impl<'a> Resolver<'a> {
32693271 // collect submodules to explore
32703272 if let Ok ( module) = name_binding. module ( ) {
32713273 // form the path
3272- let path_segments = match module. kind {
3273- _ if module. parent . is_none ( ) => path_segments. clone ( ) ,
3274- ModuleKind :: Def ( _, name) => {
3275- let mut paths = path_segments. clone ( ) ;
3276- let ident = Ident :: with_empty_ctxt ( name) ;
3277- let params = PathParameters :: none ( ) ;
3278- let segm = PathSegment {
3279- identifier : ident,
3280- parameters : params,
3281- } ;
3282- paths. push ( segm) ;
3283- paths
3284- }
3285- _ => bug ! ( ) ,
3286- } ;
3274+ let mut path_segments = path_segments. clone ( ) ;
3275+ path_segments. push ( PathSegment {
3276+ identifier : Ident :: with_empty_ctxt ( name) ,
3277+ parameters : PathParameters :: none ( ) ,
3278+ } ) ;
32873279
32883280 if !in_module_is_extern || name_binding. vis == ty:: Visibility :: Public {
32893281 // add the module to the lookup
@@ -3369,7 +3361,10 @@ impl<'a> Resolver<'a> {
33693361 if !reported_spans. insert ( span) { continue }
33703362 if binding. is_extern_crate ( ) {
33713363 // Warn when using an inaccessible extern crate.
3372- let node_id = binding. module ( ) . unwrap ( ) . extern_crate_id . unwrap ( ) ;
3364+ let node_id = match binding. kind {
3365+ NameBindingKind :: Import { directive, .. } => directive. id ,
3366+ _ => unreachable ! ( ) ,
3367+ } ;
33733368 let msg = format ! ( "extern crate `{}` is private" , name) ;
33743369 self . session . add_lint ( lint:: builtin:: INACCESSIBLE_EXTERN_CRATE , node_id, span, msg) ;
33753370 } else {
@@ -3415,7 +3410,7 @@ impl<'a> Resolver<'a> {
34153410 _ => "enum" ,
34163411 } ;
34173412
3418- let ( participle, noun) = match old_binding. is_import ( ) || old_binding . is_extern_crate ( ) {
3413+ let ( participle, noun) = match old_binding. is_import ( ) {
34193414 true => ( "imported" , "import" ) ,
34203415 false => ( "defined" , "definition" ) ,
34213416 } ;
@@ -3424,7 +3419,7 @@ impl<'a> Resolver<'a> {
34243419 let msg = {
34253420 let kind = match ( ns, old_binding. module ( ) ) {
34263421 ( ValueNS , _) => "a value" ,
3427- ( TypeNS , Ok ( module ) ) if module . extern_crate_id . is_some ( ) => "an extern crate" ,
3422+ ( TypeNS , _ ) if old_binding . is_extern_crate ( ) => "an extern crate" ,
34283423 ( TypeNS , Ok ( module) ) if module. is_normal ( ) => "a module" ,
34293424 ( TypeNS , Ok ( module) ) if module. is_trait ( ) => "a trait" ,
34303425 ( TypeNS , _) => "a type" ,
@@ -3439,7 +3434,7 @@ impl<'a> Resolver<'a> {
34393434 e. span_label ( span, & format ! ( "`{}` was already imported" , name) ) ;
34403435 e
34413436 } ,
3442- ( true , _) | ( _, true ) if binding. is_import ( ) || old_binding. is_import ( ) => {
3437+ ( true , _) | ( _, true ) if binding. is_import ( ) && old_binding. is_import ( ) => {
34433438 let mut e = struct_span_err ! ( self . session, span, E0254 , "{}" , msg) ;
34443439 e. span_label ( span, & "already imported" ) ;
34453440 e
0 commit comments