@@ -52,7 +52,10 @@ pub enum ImportDirectiveSubclass<'a> {
52
52
value_result : Cell < Result < & ' a NameBinding < ' a > , Determinacy > > ,
53
53
type_result : Cell < Result < & ' a NameBinding < ' a > , Determinacy > > ,
54
54
} ,
55
- GlobImport { is_prelude : bool } ,
55
+ GlobImport {
56
+ is_prelude : bool ,
57
+ max_vis : Cell < ty:: Visibility > , // The visibility of the greatest reexport.
58
+ } ,
56
59
}
57
60
58
61
impl < ' a > ImportDirectiveSubclass < ' a > {
@@ -276,7 +279,7 @@ impl<'a> Resolver<'a> {
276
279
}
277
280
// We don't add prelude imports to the globs since they only affect lexical scopes,
278
281
// which are not relevant to import resolution.
279
- GlobImport { is_prelude : true } => { }
282
+ GlobImport { is_prelude : true , .. } => { }
280
283
GlobImport { .. } => self . current_module . globs . borrow_mut ( ) . push ( directive) ,
281
284
}
282
285
}
@@ -292,6 +295,12 @@ impl<'a> Resolver<'a> {
292
295
binding. pseudo_vis ( )
293
296
} ;
294
297
298
+ if let GlobImport { ref max_vis, .. } = directive. subclass {
299
+ if vis == directive. vis . get ( ) || vis. is_at_least ( max_vis. get ( ) , self ) {
300
+ max_vis. set ( vis)
301
+ }
302
+ }
303
+
295
304
NameBinding {
296
305
kind : NameBindingKind :: Import {
297
306
binding : binding,
@@ -562,7 +571,15 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
562
571
let msg = "Cannot glob-import a module into itself." . into ( ) ;
563
572
return Failed ( Some ( ( directive. span , msg) ) ) ;
564
573
}
565
- GlobImport { .. } => return Success ( ( ) ) ,
574
+ GlobImport { is_prelude, ref max_vis } => {
575
+ if !is_prelude &&
576
+ max_vis. get ( ) != ty:: Visibility :: PrivateExternal && // Allow empty globs.
577
+ !max_vis. get ( ) . is_at_least ( directive. vis . get ( ) , self ) {
578
+ let msg = "A non-empty glob must import something with the glob's visibility" ;
579
+ self . session . span_err ( directive. span , msg) ;
580
+ }
581
+ return Success ( ( ) ) ;
582
+ }
566
583
} ;
567
584
568
585
for & ( ns, result) in & [ ( ValueNS , value_result) , ( TypeNS , type_result) ] {
@@ -677,7 +694,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
677
694
return ;
678
695
} else if module. def_id ( ) == directive. parent . def_id ( ) {
679
696
return ;
680
- } else if let GlobImport { is_prelude : true } = directive. subclass {
697
+ } else if let GlobImport { is_prelude : true , .. } = directive. subclass {
681
698
self . prelude = Some ( module) ;
682
699
return ;
683
700
}
0 commit comments