From fc06ea5f9c904df1325b9e886353e561ea2ba385 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Thu, 17 Mar 2016 01:13:31 +0000 Subject: [PATCH] Add a type parameter to ImportDirective --- src/librustc_resolve/lib.rs | 11 ++++++----- src/librustc_resolve/resolve_imports.rs | 17 ++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 2f6d5e1c36e0..be01880e2a91 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -828,7 +828,7 @@ pub struct ModuleS<'a> { extern_crate_id: Option, resolutions: RefCell>>, - unresolved_imports: RefCell>, + unresolved_imports: RefCell>>, // 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>>, - glob_importers: RefCell, &'a ImportDirective)>>, + glob_importers: RefCell, &'a ImportDirective<'a>)>>, resolved_globs: RefCell<(Vec> /* public */, Vec> /* private */)>, // The number of public glob imports in this module. @@ -891,7 +891,7 @@ impl<'a> ModuleS<'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>, name_bindings: arena::TypedArena>, - import_directives: arena::TypedArena, + import_directives: arena::TypedArena>, } impl<'a> ResolverArenas<'a> { @@ -1144,7 +1144,8 @@ impl<'a> ResolverArenas<'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) } } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 7c5d131dbc54..b446fa6430e8 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -57,7 +57,7 @@ impl ImportDirectiveSubclass { /// One import directive. #[derive(Debug,Clone)] -pub struct ImportDirective { +pub struct ImportDirective<'a> { module_path: Vec, 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, 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 @@ impl ImportDirective { // 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>>) -> NameBinding<'a> { + fn import(&self, binding: &'a NameBinding<'a>, privacy_error: Option>>) + -> NameBinding<'a> { let mut modifiers = match self.is_public { true => DefModifiers::PUBLIC | DefModifiers::IMPORTABLE, false => DefModifiers::empty(), @@ -292,7 +291,7 @@ impl<'a> ::ModuleS<'a> { 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 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { /// 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 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { // 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.");