提交 5f479155 编写于 作者: J Jeffrey Seyfried

Refactor `is_prelude` to only apply to glob imports

上级 aa588871
......@@ -177,13 +177,9 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent_ref: &mut Module<
}
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.
......@@ -228,23 +224,16 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent_ref: &mut Module<
}
};
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);
}
}
}
......
......@@ -41,7 +41,7 @@ pub enum ImportDirectiveSubclass {
type_determined: Cell<bool>,
value_determined: Cell<bool>,
},
GlobImport,
GlobImport { is_prelude: bool },
}
impl ImportDirectiveSubclass {
......@@ -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> {
......@@ -84,7 +83,7 @@ fn import(&'a self, binding: &'a NameBinding<'a>, privacy_error: Option<Box<Priv
}
pub fn is_glob(&self) -> bool {
match self.subclass { ImportDirectiveSubclass::GlobImport => true, _ => false }
match self.subclass { ImportDirectiveSubclass::GlobImport { .. } => true, _ => false }
}
}
......@@ -191,7 +190,7 @@ fn try_result(&self, ns: Namespace, allow_private_imports: bool)
};
let name = match directive.subclass {
SingleImport { source, .. } => source,
GlobImport => unreachable!(),
GlobImport { .. } => unreachable!(),
};
match target_module.resolve_name(name, ns, false) {
Failed(_) => {}
......@@ -282,8 +281,7 @@ pub fn add_import_directive(&self,
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),
......@@ -291,7 +289,6 @@ pub fn add_import_directive(&self,
span: span,
id: id,
vis: vis,
is_prelude: is_prelude,
});
self.unresolved_imports.borrow_mut().push(directive);
......@@ -304,8 +301,8 @@ pub fn add_import_directive(&self,
}
// 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),
}
}
......@@ -496,7 +493,7 @@ fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> ResolveResul
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.
......@@ -644,7 +641,7 @@ fn resolve_glob_import(&mut self, target_module: Module<'b>, directive: &'b Impo
}
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(());
}
......@@ -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(),
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册