@@ -73,13 +73,11 @@ pub struct ImportDirective<'a> {
73
73
impl < ' a > ImportDirective < ' a > {
74
74
// Given the binding to which this directive resolves in a particular namespace,
75
75
// this returns the binding for the name this directive defines in that namespace.
76
- fn import ( & ' a self , binding : & ' a NameBinding < ' a > , privacy_error : Option < Box < PrivacyError < ' a > > > )
77
- -> NameBinding < ' a > {
76
+ fn import ( & ' a self , binding : & ' a NameBinding < ' a > ) -> NameBinding < ' a > {
78
77
NameBinding {
79
78
kind : NameBindingKind :: Import {
80
79
binding : binding,
81
80
directive : self ,
82
- privacy_error : privacy_error,
83
81
} ,
84
82
span : self . span ,
85
83
vis : self . vis ,
@@ -328,7 +326,7 @@ impl<'a> ::ModuleS<'a> {
328
326
fn define_in_glob_importers ( & self , name : Name , ns : Namespace , binding : & ' a NameBinding < ' a > ) {
329
327
if !binding. is_importable ( ) || !binding. is_pseudo_public ( ) { return }
330
328
for & ( importer, directive) in self . glob_importers . borrow_mut ( ) . iter ( ) {
331
- let _ = importer. try_define_child ( name, ns, directive. import ( binding, None ) ) ;
329
+ let _ = importer. try_define_child ( name, ns, directive. import ( binding) ) ;
332
330
}
333
331
}
334
332
}
@@ -409,7 +407,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
409
407
span : DUMMY_SP ,
410
408
vis : ty:: Visibility :: Public ,
411
409
} ) ;
412
- let dummy_binding = directive. import ( dummy_binding, None ) ;
410
+ let dummy_binding = directive. import ( dummy_binding) ;
413
411
414
412
let _ = source_module. try_define_child ( target, ValueNS , dummy_binding. clone ( ) ) ;
415
413
let _ = source_module. try_define_child ( target, TypeNS , dummy_binding) ;
@@ -494,38 +492,37 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
494
492
self . resolver . resolve_name_in_module ( target_module, source, TypeNS , false , true ) ;
495
493
496
494
let module_ = self . resolver . current_module ;
495
+ let mut privacy_error = true ;
497
496
for & ( ns, result, determined) in & [ ( ValueNS , & value_result, value_determined) ,
498
497
( TypeNS , & type_result, type_determined) ] {
499
- if determined. get ( ) { continue }
500
- if let Indeterminate = * result { continue }
501
-
502
- determined. set ( true ) ;
503
- if let Success ( binding) = * result {
504
- if !binding. is_importable ( ) {
498
+ match * result {
499
+ Failed ( ..) if !determined. get ( ) => {
500
+ determined. set ( true ) ;
501
+ module_. update_resolution ( target, ns, |resolution| {
502
+ resolution. single_imports . directive_failed ( )
503
+ } ) ;
504
+ }
505
+ Success ( binding) if !binding. is_importable ( ) => {
505
506
let msg = format ! ( "`{}` is not directly importable" , target) ;
506
507
span_err ! ( self . resolver. session, directive. span, E0253 , "{}" , & msg) ;
507
508
// Do not import this illegal binding. Import a dummy binding and pretend
508
509
// everything is fine
509
510
self . import_dummy_binding ( module_, directive) ;
510
511
return Success ( ( ) ) ;
511
512
}
512
-
513
- let privacy_error = if !self . resolver . is_accessible ( binding. vis ) {
514
- Some ( Box :: new ( PrivacyError ( directive. span , source, binding) ) )
515
- } else {
516
- None
517
- } ;
518
-
519
- let imported_binding = directive. import ( binding, privacy_error) ;
520
- let conflict = module_. try_define_child ( target, ns, imported_binding) ;
521
- if let Err ( old_binding) = conflict {
522
- let binding = & directive. import ( binding, None ) ;
523
- self . resolver . report_conflict ( module_, target, ns, binding, old_binding) ;
513
+ Success ( binding) if !self . resolver . is_accessible ( binding. vis ) => { }
514
+ Success ( binding) if !determined. get ( ) => {
515
+ determined. set ( true ) ;
516
+ let imported_binding = directive. import ( binding) ;
517
+ let conflict = module_. try_define_child ( target, ns, imported_binding) ;
518
+ if let Err ( old_binding) = conflict {
519
+ let binding = & directive. import ( binding) ;
520
+ self . resolver . report_conflict ( module_, target, ns, binding, old_binding) ;
521
+ }
522
+ privacy_error = false ;
524
523
}
525
- } else {
526
- module_. update_resolution ( target, ns, |resolution| {
527
- resolution. single_imports . directive_failed ( ) ;
528
- } ) ;
524
+ Success ( _) => privacy_error = false ,
525
+ _ => { }
529
526
}
530
527
}
531
528
@@ -556,6 +553,14 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
556
553
_ => ( ) ,
557
554
}
558
555
556
+ if privacy_error {
557
+ for & ( ns, result) in & [ ( ValueNS , & value_result) , ( TypeNS , & type_result) ] {
558
+ let binding = match * result { Success ( binding) => binding, _ => continue } ;
559
+ self . resolver . privacy_errors . push ( PrivacyError ( directive. span , source, binding) ) ;
560
+ let _ = module_. try_define_child ( target, ns, directive. import ( binding) ) ;
561
+ }
562
+ }
563
+
559
564
match ( & value_result, & type_result) {
560
565
( & Success ( binding) , _) if !binding. pseudo_vis ( )
561
566
. is_at_least ( directive. vis , self . resolver ) &&
@@ -592,19 +597,6 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
592
597
_ => { }
593
598
}
594
599
595
- // Report a privacy error here if all successful namespaces are privacy errors.
596
- let mut privacy_error = None ;
597
- for & ns in & [ ValueNS , TypeNS ] {
598
- privacy_error = match module_. resolve_name ( target, ns, true ) {
599
- Success ( & NameBinding {
600
- kind : NameBindingKind :: Import { ref privacy_error, .. } , ..
601
- } ) => privacy_error. as_ref ( ) . map ( |error| ( * * error) . clone ( ) ) ,
602
- _ => continue ,
603
- } ;
604
- if privacy_error. is_none ( ) { break }
605
- }
606
- privacy_error. map ( |error| self . resolver . privacy_errors . push ( error) ) ;
607
-
608
600
// Record what this import resolves to for later uses in documentation,
609
601
// this may resolve to either a value or a type, but for documentation
610
602
// purposes it's good enough to just favor one over the other.
@@ -652,7 +644,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
652
644
} ) . collect :: < Vec < _ > > ( ) ;
653
645
for ( ( name, ns) , binding) in bindings {
654
646
if binding. is_importable ( ) && binding. is_pseudo_public ( ) {
655
- let _ = module_. try_define_child ( name, ns, directive. import ( binding, None ) ) ;
647
+ let _ = module_. try_define_child ( name, ns, directive. import ( binding) ) ;
656
648
}
657
649
}
658
650
0 commit comments