Skip to content

Commit c64cd86

Browse files
committed
Add field parent to ImportDirective.
1 parent d107d22 commit c64cd86

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/librustc_resolve/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ pub struct ModuleS<'a> {
756756

757757
no_implicit_prelude: Cell<bool>,
758758

759-
glob_importers: RefCell<Vec<(Module<'a>, &'a ImportDirective<'a>)>>,
759+
glob_importers: RefCell<Vec<&'a ImportDirective<'a>>>,
760760
globs: RefCell<Vec<&'a ImportDirective<'a>>>,
761761

762762
// Used to memoize the traits in this module for faster searches through all traits in scope.

src/librustc_resolve/resolve_imports.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ impl ImportDirectiveSubclass {
6363
#[derive(Debug,Clone)]
6464
pub struct ImportDirective<'a> {
6565
pub id: NodeId,
66+
parent: Module<'a>,
6667
module_path: Vec<Name>,
6768
target_module: Cell<Option<Module<'a>>>, // the resolution of `module_path`
6869
subclass: ImportDirectiveSubclass,
@@ -223,6 +224,7 @@ impl<'a> Resolver<'a> {
223224
id: NodeId,
224225
vis: ty::Visibility) {
225226
let directive = self.arenas.alloc_import_directive(ImportDirective {
227+
parent: self.current_module,
226228
module_path: module_path,
227229
target_module: Cell::new(None),
228230
subclass: subclass,
@@ -306,9 +308,9 @@ impl<'a> Resolver<'a> {
306308

307309
// Define `new_binding` in `module`s glob importers.
308310
if new_binding.is_importable() && new_binding.is_pseudo_public() {
309-
for &(importer, directive) in module.glob_importers.borrow_mut().iter() {
311+
for directive in module.glob_importers.borrow_mut().iter() {
310312
let imported_binding = self.import(new_binding, directive);
311-
let _ = self.try_define(importer, name, ns, imported_binding);
313+
let _ = self.try_define(directive.parent, name, ns, imported_binding);
312314
}
313315
}
314316

@@ -317,8 +319,6 @@ impl<'a> Resolver<'a> {
317319
}
318320

319321
struct ImportResolvingError<'a> {
320-
/// Module where the error happened
321-
source_module: Module<'a>,
322322
import_directive: &'a ImportDirective<'a>,
323323
span: Span,
324324
help: String,
@@ -402,9 +402,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
402402

403403
// Define a "dummy" resolution containing a Def::Err as a placeholder for a
404404
// failed resolution
405-
fn import_dummy_binding(&mut self,
406-
source_module: Module<'b>,
407-
directive: &'b ImportDirective<'b>) {
405+
fn import_dummy_binding(&mut self, directive: &'b ImportDirective<'b>) {
408406
if let SingleImport { target, .. } = directive.subclass {
409407
let dummy_binding = self.arenas.alloc_name_binding(NameBinding {
410408
kind: NameBindingKind::Def(Def::Err),
@@ -413,8 +411,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
413411
});
414412
let dummy_binding = self.import(dummy_binding, directive);
415413

416-
let _ = self.try_define(source_module, target, ValueNS, dummy_binding.clone());
417-
let _ = self.try_define(source_module, target, TypeNS, dummy_binding);
414+
let _ = self.try_define(directive.parent, target, ValueNS, dummy_binding.clone());
415+
let _ = self.try_define(directive.parent, target, TypeNS, dummy_binding);
418416
}
419417
}
420418

@@ -423,7 +421,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
423421
fn import_resolving_error(&mut self, e: ImportResolvingError<'b>) {
424422
// If the error is a single failed import then create a "fake" import
425423
// resolution for it so that later resolve stages won't complain.
426-
self.import_dummy_binding(e.source_module, e.import_directive);
424+
self.import_dummy_binding(e.import_directive);
427425
let path = import_path_to_string(&e.import_directive.module_path,
428426
&e.import_directive.subclass);
429427
resolve_error(self.resolver,
@@ -445,7 +443,6 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
445443
None => (import_directive.span, String::new()),
446444
};
447445
errors.push(ImportResolvingError {
448-
source_module: self.current_module,
449446
import_directive: import_directive,
450447
span: span,
451448
help: help,
@@ -511,7 +508,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
511508
.emit();
512509
// Do not import this illegal binding. Import a dummy binding and pretend
513510
// everything is fine
514-
self.import_dummy_binding(module, directive);
511+
self.import_dummy_binding(directive);
515512
return Success(());
516513
}
517514
Success(binding) if !self.is_accessible(binding.vis) => {}
@@ -635,7 +632,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
635632
}
636633

637634
// Add to target_module's glob_importers
638-
target_module.glob_importers.borrow_mut().push((module, directive));
635+
target_module.glob_importers.borrow_mut().push(directive);
639636

640637
// Ensure that `resolutions` isn't borrowed during `try_define`,
641638
// since it might get updated via a glob cycle.

0 commit comments

Comments
 (0)