Skip to content

Commit 4a3adf9

Browse files
committed
Make all visible items glob importable.
1 parent 3e34771 commit 4a3adf9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/librustc_resolve/resolve_imports.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'a> ImportDirective<'a> {
7272
// this returns the binding for the name this directive defines in that namespace.
7373
fn import(&self, binding: &'a NameBinding<'a>, privacy_error: Option<Box<PrivacyError<'a>>>)
7474
-> NameBinding<'a> {
75-
let mut modifiers = match self.is_public {
75+
let mut modifiers = match self.is_public && binding.is_public() {
7676
true => DefModifiers::PUBLIC | DefModifiers::IMPORTABLE,
7777
false => DefModifiers::empty(),
7878
};
@@ -334,9 +334,11 @@ impl<'a> ::ModuleS<'a> {
334334
}
335335

336336
fn define_in_glob_importers(&self, name: Name, ns: Namespace, binding: &'a NameBinding<'a>) {
337-
if !binding.defined_with(DefModifiers::PUBLIC | DefModifiers::IMPORTABLE) { return }
337+
if !binding.defined_with(DefModifiers::IMPORTABLE) { return }
338338
for &(importer, directive) in self.glob_importers.borrow_mut().iter() {
339-
let _ = importer.try_define_child(name, ns, directive.import(binding, None));
339+
if binding.is_public() || self.is_ancestor_of(importer) {
340+
let _ = importer.try_define_child(name, ns, directive.import(binding, None));
341+
}
340342
}
341343
}
342344
}
@@ -658,8 +660,10 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
658660
let bindings = target_module.resolutions.borrow().iter().filter_map(|(name, resolution)| {
659661
resolution.borrow().binding().map(|binding| (*name, binding))
660662
}).collect::<Vec<_>>();
663+
let allow_private_names = target_module.is_ancestor_of(module_);
661664
for ((name, ns), binding) in bindings {
662-
if binding.defined_with(DefModifiers::IMPORTABLE | DefModifiers::PUBLIC) {
665+
if !binding.defined_with(DefModifiers::IMPORTABLE) { continue }
666+
if allow_private_names || binding.is_public() {
663667
let _ = module_.try_define_child(name, ns, directive.import(binding, None));
664668
}
665669
}

0 commit comments

Comments
 (0)