提交 fc06ea5f 编写于 作者: J Jeffrey Seyfried

Add a type parameter to ImportDirective

上级 d5a91e69
......@@ -828,7 +828,7 @@ pub struct ModuleS<'a> {
extern_crate_id: Option<NodeId>,
resolutions: RefCell<HashMap<(Name, Namespace), NameResolution<'a>>>,
unresolved_imports: RefCell<Vec<&'a ImportDirective>>,
unresolved_imports: RefCell<Vec<&'a ImportDirective<'a>>>,
// The module children of this node, including normal modules and anonymous modules.
// Anonymous children are pseudo-modules that are implicitly created around items
......@@ -848,7 +848,7 @@ pub struct ModuleS<'a> {
prelude: RefCell<Option<Module<'a>>>,
glob_importers: RefCell<Vec<(Module<'a>, &'a ImportDirective)>>,
glob_importers: RefCell<Vec<(Module<'a>, &'a ImportDirective<'a>)>>,
resolved_globs: RefCell<(Vec<Module<'a>> /* public */, Vec<Module<'a>> /* private */)>,
// The number of public glob imports in this module.
......@@ -891,7 +891,7 @@ fn new(parent_link: ParentLink<'a>,
}
}
fn add_import_directive(&self, import_directive: ImportDirective) {
fn add_import_directive(&self, import_directive: ImportDirective<'a>) {
let import_directive = self.arenas.alloc_import_directive(import_directive);
self.unresolved_imports.borrow_mut().push(import_directive);
}
......@@ -1134,7 +1134,7 @@ pub struct Resolver<'a, 'tcx: 'a> {
struct ResolverArenas<'a> {
modules: arena::TypedArena<ModuleS<'a>>,
name_bindings: arena::TypedArena<NameBinding<'a>>,
import_directives: arena::TypedArena<ImportDirective>,
import_directives: arena::TypedArena<ImportDirective<'a>>,
}
impl<'a> ResolverArenas<'a> {
......@@ -1144,7 +1144,8 @@ fn alloc_module(&'a self, module: ModuleS<'a>) -> Module<'a> {
fn alloc_name_binding(&'a self, name_binding: NameBinding<'a>) -> &'a NameBinding<'a> {
self.name_bindings.alloc(name_binding)
}
fn alloc_import_directive(&'a self, import_directive: ImportDirective) -> &'a ImportDirective {
fn alloc_import_directive(&'a self, import_directive: ImportDirective<'a>)
-> &'a ImportDirective {
self.import_directives.alloc(import_directive)
}
}
......
......@@ -57,7 +57,7 @@ pub fn single(target: Name, source: Name) -> Self {
/// One import directive.
#[derive(Debug,Clone)]
pub struct ImportDirective {
pub struct ImportDirective<'a> {
module_path: Vec<Name>,
subclass: ImportDirectiveSubclass,
span: Span,
......@@ -66,14 +66,14 @@ pub struct ImportDirective {
is_prelude: bool,
}
impl ImportDirective {
impl<'a> ImportDirective<'a> {
pub fn new(module_path: Vec<Name>,
subclass: ImportDirectiveSubclass,
span: Span,
id: NodeId,
is_public: bool,
is_prelude: bool)
-> ImportDirective {
-> Self {
ImportDirective {
module_path: module_path,
subclass: subclass,
......@@ -86,9 +86,8 @@ pub fn new(module_path: Vec<Name>,
// Given the binding to which this directive resolves in a particular namespace,
// this returns the binding for the name this directive defines in that namespace.
fn import<'a>(&self,
binding: &'a NameBinding<'a>,
privacy_error: Option<Box<PrivacyError<'a>>>) -> NameBinding<'a> {
fn import(&self, binding: &'a NameBinding<'a>, privacy_error: Option<Box<PrivacyError<'a>>>)
-> NameBinding<'a> {
let mut modifiers = match self.is_public {
true => DefModifiers::PUBLIC | DefModifiers::IMPORTABLE,
false => DefModifiers::empty(),
......@@ -292,7 +291,7 @@ fn define_in_glob_importers(&self, name: Name, ns: Namespace, binding: &'a NameB
struct ImportResolvingError<'a> {
/// Module where the error happened
source_module: Module<'a>,
import_directive: &'a ImportDirective,
import_directive: &'a ImportDirective<'a>,
span: Span,
help: String,
}
......@@ -424,7 +423,7 @@ fn resolve_imports_in_current_module(&mut self, errors: &mut Vec<ImportResolving
/// don't know whether the name exists at the moment due to other
/// currently-unresolved imports, or success if we know the name exists.
/// If successful, the resolved bindings are written into the module.
fn resolve_import(&mut self, directive: &'b ImportDirective) -> ResolveResult<()> {
fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> ResolveResult<()> {
debug!("(resolving import for module) resolving import `{}::...` in `{}`",
names_to_string(&directive.module_path),
module_to_string(self.resolver.current_module));
......@@ -579,7 +578,7 @@ fn resolve_import(&mut self, directive: &'b ImportDirective) -> ResolveResult<()
// succeeds or bails out (as importing * from an empty module or a module
// that exports nothing is valid). target_module is the module we are
// actually importing, i.e., `foo` in `use foo::*`.
fn resolve_glob_import(&mut self, target_module: Module<'b>, directive: &'b ImportDirective)
fn resolve_glob_import(&mut self, target_module: Module<'b>, directive: &'b ImportDirective<'b>)
-> ResolveResult<()> {
if let Some(Def::Trait(_)) = target_module.def {
self.resolver.session.span_err(directive.span, "items in traits are not importable.");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册