Refactor away resolve_imports::Shadowable and rename shadowable -> is_prelude
This commit is contained in:
parent
64a13a4660
commit
21064d097e
|
@ -22,7 +22,6 @@ use {NameBinding, NameBindingKind};
|
||||||
use module_to_string;
|
use module_to_string;
|
||||||
use ParentLink::{ModuleParentLink, BlockParentLink};
|
use ParentLink::{ModuleParentLink, BlockParentLink};
|
||||||
use Resolver;
|
use Resolver;
|
||||||
use resolve_imports::Shadowable;
|
|
||||||
use {resolve_error, resolve_struct_error, ResolutionError};
|
use {resolve_error, resolve_struct_error, ResolutionError};
|
||||||
|
|
||||||
use rustc::middle::cstore::{CrateStore, ChildItem, DlDef, DlField, DlImpl};
|
use rustc::middle::cstore::{CrateStore, ChildItem, DlDef, DlField, DlImpl};
|
||||||
|
@ -161,14 +160,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Build up the import directives.
|
// Build up the import directives.
|
||||||
let shadowable = item.attrs.iter().any(|attr| {
|
let is_prelude = item.attrs.iter().any(|attr| {
|
||||||
attr.name() == special_idents::prelude_import.name.as_str()
|
attr.name() == special_idents::prelude_import.name.as_str()
|
||||||
});
|
});
|
||||||
let shadowable = if shadowable {
|
|
||||||
Shadowable::Always
|
|
||||||
} else {
|
|
||||||
Shadowable::Never
|
|
||||||
};
|
|
||||||
|
|
||||||
match view_path.node {
|
match view_path.node {
|
||||||
ViewPathSimple(binding, ref full_path) => {
|
ViewPathSimple(binding, ref full_path) => {
|
||||||
|
@ -186,7 +180,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||||
view_path.span,
|
view_path.span,
|
||||||
item.id,
|
item.id,
|
||||||
is_public,
|
is_public,
|
||||||
shadowable);
|
is_prelude);
|
||||||
}
|
}
|
||||||
ViewPathList(_, ref source_items) => {
|
ViewPathList(_, ref source_items) => {
|
||||||
// Make sure there's at most one `mod` import in the list.
|
// Make sure there's at most one `mod` import in the list.
|
||||||
|
@ -237,7 +231,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||||
source_item.span,
|
source_item.span,
|
||||||
source_item.node.id(),
|
source_item.node.id(),
|
||||||
is_public,
|
is_public,
|
||||||
shadowable);
|
is_prelude);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ViewPathGlob(_) => {
|
ViewPathGlob(_) => {
|
||||||
|
@ -247,7 +241,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||||
view_path.span,
|
view_path.span,
|
||||||
item.id,
|
item.id,
|
||||||
is_public,
|
is_public,
|
||||||
shadowable);
|
is_prelude);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parent
|
parent
|
||||||
|
@ -631,7 +625,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||||
span: Span,
|
span: Span,
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
is_public: bool,
|
is_public: bool,
|
||||||
shadowable: Shadowable) {
|
is_prelude: bool) {
|
||||||
// Bump the reference count on the name. Or, if this is a glob, set
|
// Bump the reference count on the name. Or, if this is a glob, set
|
||||||
// the appropriate flag.
|
// the appropriate flag.
|
||||||
|
|
||||||
|
@ -648,7 +642,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let directive =
|
let directive =
|
||||||
ImportDirective::new(module_path, subclass, span, id, is_public, shadowable);
|
ImportDirective::new(module_path, subclass, span, id, is_public, is_prelude);
|
||||||
module_.add_import_directive(directive);
|
module_.add_import_directive(directive);
|
||||||
self.unresolved_imports += 1;
|
self.unresolved_imports += 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,13 +57,6 @@ impl ImportDirectiveSubclass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether an import can be shadowed by another import.
|
|
||||||
#[derive(Debug,PartialEq,Clone,Copy)]
|
|
||||||
pub enum Shadowable {
|
|
||||||
Always,
|
|
||||||
Never,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One import directive.
|
/// One import directive.
|
||||||
#[derive(Debug,Clone)]
|
#[derive(Debug,Clone)]
|
||||||
pub struct ImportDirective {
|
pub struct ImportDirective {
|
||||||
|
@ -72,7 +65,7 @@ pub struct ImportDirective {
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub id: NodeId,
|
pub id: NodeId,
|
||||||
pub is_public: bool, // see note in ImportResolutionPerNamespace about how to use this
|
pub is_public: bool, // see note in ImportResolutionPerNamespace about how to use this
|
||||||
pub shadowable: Shadowable,
|
pub is_prelude: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ImportDirective {
|
impl ImportDirective {
|
||||||
|
@ -81,7 +74,7 @@ impl ImportDirective {
|
||||||
span: Span,
|
span: Span,
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
is_public: bool,
|
is_public: bool,
|
||||||
shadowable: Shadowable)
|
is_prelude: bool)
|
||||||
-> ImportDirective {
|
-> ImportDirective {
|
||||||
ImportDirective {
|
ImportDirective {
|
||||||
module_path: module_path,
|
module_path: module_path,
|
||||||
|
@ -89,7 +82,7 @@ impl ImportDirective {
|
||||||
span: span,
|
span: span,
|
||||||
id: id,
|
id: id,
|
||||||
is_public: is_public,
|
is_public: is_public,
|
||||||
shadowable: shadowable,
|
is_prelude: is_prelude,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +98,7 @@ impl ImportDirective {
|
||||||
if let GlobImport = self.subclass {
|
if let GlobImport = self.subclass {
|
||||||
modifiers = modifiers | DefModifiers::GLOB_IMPORTED;
|
modifiers = modifiers | DefModifiers::GLOB_IMPORTED;
|
||||||
}
|
}
|
||||||
if self.shadowable == Shadowable::Always {
|
if self.is_prelude {
|
||||||
modifiers = modifiers | DefModifiers::PRELUDE;
|
modifiers = modifiers | DefModifiers::PRELUDE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue