提交 097b6d62 编写于 作者: J Jeffrey Seyfried

item_like_imports: Allow glob imports with a given visibility

to reexport some (but not all) names with less visibility.
上级 c56a5afd
......@@ -26,6 +26,8 @@
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
use rustc::ty::{self, VariantKind};
use std::cell::Cell;
use syntax::ast::Name;
use syntax::attr;
use syntax::parse::token;
......@@ -176,7 +178,10 @@ fn build_reduced_graph_for_item(&mut self, item: &Item) {
}
}
ViewPathGlob(_) => {
let subclass = GlobImport { is_prelude: is_prelude };
let subclass = GlobImport {
is_prelude: is_prelude,
max_vis: Cell::new(ty::Visibility::PrivateExternal),
};
let span = view_path.span;
self.add_import_directive(module_path, subclass, span, item.id, vis);
}
......
......@@ -52,7 +52,10 @@ pub enum ImportDirectiveSubclass<'a> {
value_result: Cell<Result<&'a NameBinding<'a>, Determinacy>>,
type_result: Cell<Result<&'a NameBinding<'a>, Determinacy>>,
},
GlobImport { is_prelude: bool },
GlobImport {
is_prelude: bool,
max_vis: Cell<ty::Visibility>, // The visibility of the greatest reexport.
},
}
impl<'a> ImportDirectiveSubclass<'a> {
......@@ -276,7 +279,7 @@ pub fn add_import_directive(&mut self,
}
// We don't add prelude imports to the globs since they only affect lexical scopes,
// which are not relevant to import resolution.
GlobImport { is_prelude: true } => {}
GlobImport { is_prelude: true, .. } => {}
GlobImport { .. } => self.current_module.globs.borrow_mut().push(directive),
}
}
......@@ -292,6 +295,12 @@ fn import(&mut self, binding: &'a NameBinding<'a>, directive: &'a ImportDirectiv
binding.pseudo_vis()
};
if let GlobImport { ref max_vis, .. } = directive.subclass {
if vis == directive.vis.get() || vis.is_at_least(max_vis.get(), self) {
max_vis.set(vis)
}
}
NameBinding {
kind: NameBindingKind::Import {
binding: binding,
......@@ -562,7 +571,15 @@ fn finalize_import(&mut self, directive: &'b ImportDirective<'b>) -> ResolveResu
let msg = "Cannot glob-import a module into itself.".into();
return Failed(Some((directive.span, msg)));
}
GlobImport { .. } => return Success(()),
GlobImport { is_prelude, ref max_vis } => {
if !is_prelude &&
max_vis.get() != ty::Visibility::PrivateExternal && // Allow empty globs.
!max_vis.get().is_at_least(directive.vis.get(), self) {
let msg = "A non-empty glob must import something with the glob's visibility";
self.session.span_err(directive.span, msg);
}
return Success(());
}
};
for &(ns, result) in &[(ValueNS, value_result), (TypeNS, type_result)] {
......@@ -677,7 +694,7 @@ fn resolve_glob_import(&mut self, directive: &'b ImportDirective<'b>) {
return;
} else if module.def_id() == directive.parent.def_id() {
return;
} else if let GlobImport { is_prelude: true } = directive.subclass {
} else if let GlobImport { is_prelude: true, .. } = directive.subclass {
self.prelude = Some(module);
return;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册