@@ -285,13 +285,20 @@ impl<'a> Resolver<'a> {
285
285
// return the corresponding binding defined by the import directive.
286
286
fn import ( & mut self , binding : & ' a NameBinding < ' a > , directive : & ' a ImportDirective < ' a > )
287
287
-> NameBinding < ' a > {
288
+ let vis = if binding. pseudo_vis ( ) . is_at_least ( directive. vis . get ( ) , self ) ||
289
+ !directive. is_glob ( ) && binding. is_extern_crate ( ) { // c.f. `PRIVATE_IN_PUBLIC`
290
+ directive. vis . get ( )
291
+ } else {
292
+ binding. pseudo_vis ( )
293
+ } ;
294
+
288
295
NameBinding {
289
296
kind : NameBindingKind :: Import {
290
297
binding : binding,
291
298
directive : directive,
292
299
} ,
293
300
span : directive. span ,
294
- vis : directive . vis . get ( ) ,
301
+ vis : vis,
295
302
}
296
303
}
297
304
@@ -597,22 +604,44 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
597
604
}
598
605
}
599
606
607
+ let session = self . session ;
608
+ let reexport_error = || {
609
+ let msg = format ! ( "`{}` is private, and cannot be reexported" , name) ;
610
+ let note_msg =
611
+ format ! ( "consider marking `{}` as `pub` in the imported module" , name) ;
612
+ struct_span_err ! ( session, directive. span, E0364 , "{}" , & msg)
613
+ . span_note ( directive. span , & note_msg)
614
+ . emit ( ) ;
615
+ } ;
616
+
617
+ let extern_crate_lint = || {
618
+ let msg = format ! ( "extern crate `{}` is private, and cannot be reexported \
619
+ (error E0364), consider declaring with `pub`",
620
+ name) ;
621
+ session. add_lint ( PRIVATE_IN_PUBLIC , directive. id , directive. span , msg) ;
622
+ } ;
623
+
600
624
match ( value_result, type_result) {
625
+ // With `#![feature(item_like_imports)]`, all namespaces
626
+ // must be re-exported with extra visibility for an error to occur.
627
+ ( Ok ( value_binding) , Ok ( type_binding) ) if self . new_import_semantics => {
628
+ let vis = directive. vis . get ( ) ;
629
+ if !value_binding. pseudo_vis ( ) . is_at_least ( vis, self ) &&
630
+ !type_binding. pseudo_vis ( ) . is_at_least ( vis, self ) {
631
+ reexport_error ( ) ;
632
+ } else if type_binding. is_extern_crate ( ) &&
633
+ !type_binding. vis . is_at_least ( vis, self ) {
634
+ extern_crate_lint ( ) ;
635
+ }
636
+ }
637
+
601
638
( Ok ( binding) , _) if !binding. pseudo_vis ( ) . is_at_least ( directive. vis . get ( ) , self ) => {
602
- let msg = format ! ( "`{}` is private, and cannot be reexported" , name) ;
603
- let note_msg =
604
- format ! ( "consider marking `{}` as `pub` in the imported module" , name) ;
605
- struct_span_err ! ( self . session, directive. span, E0364 , "{}" , & msg)
606
- . span_note ( directive. span , & note_msg)
607
- . emit ( ) ;
639
+ reexport_error ( ) ;
608
640
}
609
641
610
642
( _, Ok ( binding) ) if !binding. pseudo_vis ( ) . is_at_least ( directive. vis . get ( ) , self ) => {
611
643
if binding. is_extern_crate ( ) {
612
- let msg = format ! ( "extern crate `{}` is private, and cannot be reexported \
613
- (error E0364), consider declaring with `pub`",
614
- name) ;
615
- self . session . add_lint ( PRIVATE_IN_PUBLIC , directive. id , directive. span , msg) ;
644
+ extern_crate_lint ( ) ;
616
645
} else {
617
646
struct_span_err ! ( self . session, directive. span, E0365 ,
618
647
"`{}` is private, and cannot be reexported" , name)
0 commit comments