@@ -76,7 +76,7 @@ use std::fmt;
76
76
use std:: mem:: replace;
77
77
use std:: rc:: Rc ;
78
78
79
- use resolve_imports:: { ImportDirective , NameResolution } ;
79
+ use resolve_imports:: { ImportDirective , ImportDirectiveSubclass , NameResolution } ;
80
80
use macros:: { InvocationData , LegacyBinding , LegacyScope } ;
81
81
82
82
// NB: This module needs to be declared first so diagnostics are
@@ -796,10 +796,6 @@ pub struct ModuleS<'a> {
796
796
// The node id of the closest normal module (`mod`) ancestor (including this module).
797
797
normal_ancestor_id : Option < NodeId > ,
798
798
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
-
803
799
resolutions : RefCell < FxHashMap < ( Name , Namespace ) , & ' a RefCell < NameResolution < ' a > > > > ,
804
800
805
801
no_implicit_prelude : bool ,
@@ -824,7 +820,6 @@ impl<'a> ModuleS<'a> {
824
820
parent : parent,
825
821
kind : kind,
826
822
normal_ancestor_id : None ,
827
- extern_crate_id : None ,
828
823
resolutions : RefCell :: new ( FxHashMap ( ) ) ,
829
824
no_implicit_prelude : false ,
830
825
glob_importers : RefCell :: new ( Vec :: new ( ) ) ,
@@ -953,7 +948,14 @@ impl<'a> NameBinding<'a> {
953
948
}
954
949
955
950
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
+ }
957
959
}
958
960
959
961
fn is_import ( & self ) -> bool {
@@ -3233,7 +3235,7 @@ impl<'a> Resolver<'a> {
3233
3235
in_module. for_each_child ( |name, ns, name_binding| {
3234
3236
3235
3237
// avoid imports entirely
3236
- if name_binding. is_import ( ) { return ; }
3238
+ if name_binding. is_import ( ) && !name_binding . is_extern_crate ( ) { return ; }
3237
3239
3238
3240
// collect results based on the filter function
3239
3241
if name == lookup_name && ns == namespace {
@@ -3269,21 +3271,11 @@ impl<'a> Resolver<'a> {
3269
3271
// collect submodules to explore
3270
3272
if let Ok ( module) = name_binding. module ( ) {
3271
3273
// 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
+ } ) ;
3287
3279
3288
3280
if !in_module_is_extern || name_binding. vis == ty:: Visibility :: Public {
3289
3281
// add the module to the lookup
@@ -3369,7 +3361,10 @@ impl<'a> Resolver<'a> {
3369
3361
if !reported_spans. insert ( span) { continue }
3370
3362
if binding. is_extern_crate ( ) {
3371
3363
// 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
+ } ;
3373
3368
let msg = format ! ( "extern crate `{}` is private" , name) ;
3374
3369
self . session . add_lint ( lint:: builtin:: INACCESSIBLE_EXTERN_CRATE , node_id, span, msg) ;
3375
3370
} else {
@@ -3415,7 +3410,7 @@ impl<'a> Resolver<'a> {
3415
3410
_ => "enum" ,
3416
3411
} ;
3417
3412
3418
- let ( participle, noun) = match old_binding. is_import ( ) || old_binding . is_extern_crate ( ) {
3413
+ let ( participle, noun) = match old_binding. is_import ( ) {
3419
3414
true => ( "imported" , "import" ) ,
3420
3415
false => ( "defined" , "definition" ) ,
3421
3416
} ;
@@ -3424,7 +3419,7 @@ impl<'a> Resolver<'a> {
3424
3419
let msg = {
3425
3420
let kind = match ( ns, old_binding. module ( ) ) {
3426
3421
( 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" ,
3428
3423
( TypeNS , Ok ( module) ) if module. is_normal ( ) => "a module" ,
3429
3424
( TypeNS , Ok ( module) ) if module. is_trait ( ) => "a trait" ,
3430
3425
( TypeNS , _) => "a type" ,
@@ -3439,7 +3434,7 @@ impl<'a> Resolver<'a> {
3439
3434
e. span_label ( span, & format ! ( "`{}` was already imported" , name) ) ;
3440
3435
e
3441
3436
} ,
3442
- ( true , _) | ( _, true ) if binding. is_import ( ) || old_binding. is_import ( ) => {
3437
+ ( true , _) | ( _, true ) if binding. is_import ( ) && old_binding. is_import ( ) => {
3443
3438
let mut e = struct_span_err ! ( self . session, span, E0254 , "{}" , msg) ;
3444
3439
e. span_label ( span, & "already imported" ) ;
3445
3440
e
0 commit comments