Skip to content

Commit

Permalink
Refactor is_prelude to only apply to glob imports
Browse files Browse the repository at this point in the history
  • Loading branch information
jseyfried committed Apr 17, 2016
1 parent aa58887 commit 5f47915
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
25 changes: 7 additions & 18 deletions src/librustc_resolve/build_reduced_graph.rs
Expand Up @@ -177,13 +177,9 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
}

let subclass = ImportDirectiveSubclass::single(binding, source_name);
let span = view_path.span;
parent.add_import_directive(module_path, subclass, span, item.id, vis);
self.unresolved_imports += 1;
parent.add_import_directive(module_path,
subclass,
view_path.span,
item.id,
vis,
is_prelude);
}
ViewPathList(_, ref source_items) => {
// Make sure there's at most one `mod` import in the list.
Expand Down Expand Up @@ -228,23 +224,16 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
}
};
let subclass = ImportDirectiveSubclass::single(rename, name);
let (span, id) = (source_item.span, source_item.node.id());
parent.add_import_directive(module_path, subclass, span, id, vis);
self.unresolved_imports += 1;
parent.add_import_directive(module_path,
subclass,
source_item.span,
source_item.node.id(),
vis,
is_prelude);
}
}
ViewPathGlob(_) => {
let subclass = GlobImport { is_prelude: is_prelude };
let span = view_path.span;
parent.add_import_directive(module_path, subclass, span, item.id, vis);
self.unresolved_imports += 1;
parent.add_import_directive(module_path,
GlobImport,
view_path.span,
item.id,
vis,
is_prelude);
}
}
}
Expand Down
21 changes: 9 additions & 12 deletions src/librustc_resolve/resolve_imports.rs
Expand Up @@ -41,7 +41,7 @@ pub enum ImportDirectiveSubclass {
type_determined: Cell<bool>,
value_determined: Cell<bool>,
},
GlobImport,
GlobImport { is_prelude: bool },
}

impl ImportDirectiveSubclass {
Expand All @@ -64,7 +64,6 @@ pub struct ImportDirective<'a> {
subclass: ImportDirectiveSubclass,
span: Span,
vis: ty::Visibility, // see note in ImportResolutionPerNamespace about how to use this
is_prelude: bool,
}

impl<'a> ImportDirective<'a> {
Expand All @@ -84,7 +83,7 @@ impl<'a> ImportDirective<'a> {
}

pub fn is_glob(&self) -> bool {
match self.subclass { ImportDirectiveSubclass::GlobImport => true, _ => false }
match self.subclass { ImportDirectiveSubclass::GlobImport { .. } => true, _ => false }
}
}

Expand Down Expand Up @@ -191,7 +190,7 @@ impl<'a> NameResolution<'a> {
};
let name = match directive.subclass {
SingleImport { source, .. } => source,
GlobImport => unreachable!(),
GlobImport { .. } => unreachable!(),
};
match target_module.resolve_name(name, ns, false) {
Failed(_) => {}
Expand Down Expand Up @@ -282,16 +281,14 @@ impl<'a> ::ModuleS<'a> {
subclass: ImportDirectiveSubclass,
span: Span,
id: NodeId,
vis: ty::Visibility,
is_prelude: bool) {
vis: ty::Visibility) {
let directive = self.arenas.alloc_import_directive(ImportDirective {
module_path: module_path,
target_module: Cell::new(None),
subclass: subclass,
span: span,
id: id,
vis: vis,
is_prelude: is_prelude,
});

self.unresolved_imports.borrow_mut().push(directive);
Expand All @@ -304,8 +301,8 @@ impl<'a> ::ModuleS<'a> {
}
// We don't add prelude imports to the globs since they only affect lexical scopes,
// which are not relevant to import resolution.
GlobImport if directive.is_prelude => {}
GlobImport => self.globs.borrow_mut().push(directive),
GlobImport { is_prelude: true } => {}
GlobImport { .. } => self.globs.borrow_mut().push(directive),
}
}

Expand Down Expand Up @@ -496,7 +493,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
let (source, target, value_determined, type_determined) = match directive.subclass {
SingleImport { source, target, ref value_determined, ref type_determined } =>
(source, target, value_determined, type_determined),
GlobImport => return self.resolve_glob_import(target_module, directive),
GlobImport { .. } => return self.resolve_glob_import(target_module, directive),
};

// We need to resolve both namespaces for this to succeed.
Expand Down Expand Up @@ -644,7 +641,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
}
self.resolver.populate_module_if_necessary(target_module);

if directive.is_prelude {
if let GlobImport { is_prelude: true } = directive.subclass {
*module_.prelude.borrow_mut() = Some(target_module);
return Success(());
}
Expand Down Expand Up @@ -747,7 +744,7 @@ fn import_path_to_string(names: &[Name], subclass: &ImportDirectiveSubclass) ->
fn import_directive_subclass_to_string(subclass: &ImportDirectiveSubclass) -> String {
match *subclass {
SingleImport { source, .. } => source.to_string(),
GlobImport => "*".to_string(),
GlobImport { .. } => "*".to_string(),
}
}

Expand Down

0 comments on commit 5f47915

Please sign in to comment.