Auto merge of #29387 - little-dude:rustfmt_librustc_resolve, r=nrc
Another rustfmt PR. I ran rustfmt, then split the changes in multiple commits. First commit are the non-problematic changed. The others are all the little weirdness that caught my attention and could be discussed.
This commit is contained in:
commit
b7845f93b5
@ -66,7 +66,7 @@ enum DuplicateCheckingMode {
|
||||
ForbidDuplicateTypesAndModules,
|
||||
ForbidDuplicateValues,
|
||||
ForbidDuplicateTypesAndValues,
|
||||
OverwriteDuplicates
|
||||
OverwriteDuplicates,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
@ -74,19 +74,19 @@ enum NamespaceError {
|
||||
NoError,
|
||||
ModuleError,
|
||||
TypeError,
|
||||
ValueError
|
||||
ValueError,
|
||||
}
|
||||
|
||||
fn namespace_error_to_string(ns: NamespaceError) -> &'static str {
|
||||
match ns {
|
||||
NoError => "",
|
||||
NoError => "",
|
||||
ModuleError | TypeError => "type or module",
|
||||
ValueError => "value",
|
||||
ValueError => "value",
|
||||
}
|
||||
}
|
||||
|
||||
struct GraphBuilder<'a, 'b:'a, 'tcx:'b> {
|
||||
resolver: &'a mut Resolver<'b, 'tcx>
|
||||
struct GraphBuilder<'a, 'b: 'a, 'tcx: 'b> {
|
||||
resolver: &'a mut Resolver<'b, 'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'b:'a, 'tcx:'b> Deref for GraphBuilder<'a, 'b, 'tcx> {
|
||||
@ -109,7 +109,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
let parent = self.graph_root.get_module();
|
||||
let mut visitor = BuildReducedGraphVisitor {
|
||||
builder: self,
|
||||
parent: parent
|
||||
parent: parent,
|
||||
};
|
||||
visit::walk_crate(&mut visitor, krate);
|
||||
}
|
||||
@ -135,9 +135,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
// child name directly. Otherwise, we create or reuse an anonymous
|
||||
// module and add the child to that.
|
||||
|
||||
self.check_for_conflicts_between_external_crates_and_items(&**parent,
|
||||
name,
|
||||
sp);
|
||||
self.check_for_conflicts_between_external_crates_and_items(&**parent, name, sp);
|
||||
|
||||
// Add or reuse the child.
|
||||
let child = parent.children.borrow().get(&name).cloned();
|
||||
@ -194,14 +192,14 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
n = Some(TypeNS);
|
||||
duplicate_type = TypeError;
|
||||
}
|
||||
};
|
||||
}
|
||||
if child.defined_in_namespace(ValueNS) {
|
||||
duplicate_type = ValueError;
|
||||
n = Some(ValueNS);
|
||||
}
|
||||
n
|
||||
}
|
||||
OverwriteDuplicates => None
|
||||
OverwriteDuplicates => None,
|
||||
};
|
||||
if duplicate_type != NoError {
|
||||
// Return an error here by looking up the namespace that
|
||||
@ -218,7 +216,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
let r = child.span_for_namespace(ns);
|
||||
if let Some(sp) = r {
|
||||
self.session.span_note(sp,
|
||||
&format!("first definition of {} `{}` here",
|
||||
&format!("first definition of {} `{}` here",
|
||||
namespace_error_to_string(duplicate_type),
|
||||
name));
|
||||
}
|
||||
@ -278,15 +276,20 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
let module_path = match view_path.node {
|
||||
ViewPathSimple(_, ref full_path) => {
|
||||
full_path.segments
|
||||
.split_last().unwrap().1
|
||||
.iter().map(|seg| seg.identifier.name)
|
||||
.collect()
|
||||
.split_last()
|
||||
.unwrap()
|
||||
.1
|
||||
.iter()
|
||||
.map(|seg| seg.identifier.name)
|
||||
.collect()
|
||||
}
|
||||
|
||||
ViewPathGlob(ref module_ident_path) |
|
||||
ViewPathList(ref module_ident_path, _) => {
|
||||
module_ident_path.segments
|
||||
.iter().map(|seg| seg.identifier.name).collect()
|
||||
.iter()
|
||||
.map(|seg| seg.identifier.name)
|
||||
.collect()
|
||||
}
|
||||
};
|
||||
|
||||
@ -302,8 +305,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
|
||||
match view_path.node {
|
||||
ViewPathSimple(binding, ref full_path) => {
|
||||
let source_name =
|
||||
full_path.segments.last().unwrap().identifier.name;
|
||||
let source_name = full_path.segments.last().unwrap().identifier.name;
|
||||
if source_name.as_str() == "mod" || source_name.as_str() == "self" {
|
||||
resolve_error(self,
|
||||
view_path.span,
|
||||
@ -321,19 +323,21 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
}
|
||||
ViewPathList(_, ref source_items) => {
|
||||
// Make sure there's at most one `mod` import in the list.
|
||||
let mod_spans = source_items.iter().filter_map(|item| match item.node {
|
||||
PathListMod { .. } => Some(item.span),
|
||||
_ => None
|
||||
}).collect::<Vec<Span>>();
|
||||
let mod_spans = source_items.iter()
|
||||
.filter_map(|item| {
|
||||
match item.node {
|
||||
PathListMod { .. } => Some(item.span),
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
.collect::<Vec<Span>>();
|
||||
if mod_spans.len() > 1 {
|
||||
resolve_error(
|
||||
self,
|
||||
mod_spans[0],
|
||||
ResolutionError::SelfImportCanOnlyAppearOnceInTheList
|
||||
);
|
||||
resolve_error(self,
|
||||
mod_spans[0],
|
||||
ResolutionError::SelfImportCanOnlyAppearOnceInTheList);
|
||||
for other_span in mod_spans.iter().skip(1) {
|
||||
self.session.span_note(*other_span,
|
||||
"another `self` import appears here");
|
||||
self.session
|
||||
.span_note(*other_span, "another `self` import appears here");
|
||||
}
|
||||
}
|
||||
|
||||
@ -359,14 +363,13 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
(module_path.to_vec(), name, rename)
|
||||
}
|
||||
};
|
||||
self.build_import_directive(
|
||||
&**parent,
|
||||
module_path,
|
||||
SingleImport(rename, name),
|
||||
source_item.span,
|
||||
source_item.node.id(),
|
||||
is_public,
|
||||
shadowable);
|
||||
self.build_import_directive(&**parent,
|
||||
module_path,
|
||||
SingleImport(rename, name),
|
||||
source_item.span,
|
||||
source_item.node.id(),
|
||||
is_public,
|
||||
shadowable);
|
||||
}
|
||||
}
|
||||
ViewPathGlob(_) => {
|
||||
@ -383,9 +386,13 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
}
|
||||
|
||||
ItemExternCrate(_) => {
|
||||
// n.b. we don't need to look at the path option here, because cstore already did
|
||||
// n.b. we don't need to look at the path option here, because cstore already
|
||||
// did
|
||||
if let Some(crate_id) = self.session.cstore.find_extern_mod_stmt_cnum(item.id) {
|
||||
let def_id = DefId { krate: crate_id, index: CRATE_DEF_INDEX };
|
||||
let def_id = DefId {
|
||||
krate: crate_id,
|
||||
index: CRATE_DEF_INDEX,
|
||||
};
|
||||
self.external_exports.insert(def_id);
|
||||
let parent_link = ModuleParentLink(Rc::downgrade(parent), name);
|
||||
let external_module = Rc::new(Module::new(parent_link,
|
||||
@ -394,9 +401,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
false,
|
||||
true));
|
||||
debug!("(build reduced graph for item) found extern `{}`",
|
||||
module_to_string(&*external_module));
|
||||
module_to_string(&*external_module));
|
||||
self.check_for_conflicts_between_external_crates(&**parent, name, sp);
|
||||
parent.external_module_children.borrow_mut()
|
||||
parent.external_module_children
|
||||
.borrow_mut()
|
||||
.insert(name, external_module.clone());
|
||||
self.build_reduced_graph_for_external_crate(&external_module);
|
||||
}
|
||||
@ -407,20 +415,19 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
let child = parent.children.borrow().get(&name).cloned();
|
||||
if let Some(child) = child {
|
||||
// check if there's struct of the same name already defined
|
||||
if child.defined_in_namespace(TypeNS)
|
||||
&& child.get_module_if_available().is_none() {
|
||||
self.session.span_warn(sp, &format!(
|
||||
"duplicate definition of {} `{}`. \
|
||||
Defining a module and a struct with \
|
||||
the same name will be disallowed \
|
||||
soon.",
|
||||
namespace_error_to_string(TypeError),
|
||||
name));
|
||||
if child.defined_in_namespace(TypeNS) &&
|
||||
child.get_module_if_available().is_none() {
|
||||
self.session.span_warn(sp,
|
||||
&format!("duplicate definition of {} `{}`. \
|
||||
Defining a module and a struct with \
|
||||
the same name will be disallowed soon.",
|
||||
namespace_error_to_string(TypeError),
|
||||
name));
|
||||
{
|
||||
let r = child.span_for_namespace(TypeNS);
|
||||
if let Some(sp) = r {
|
||||
self.session.span_note(sp,
|
||||
&format!("first definition of {} `{}` here",
|
||||
&format!("first definition of {} `{}` here",
|
||||
namespace_error_to_string(TypeError),
|
||||
name));
|
||||
}
|
||||
@ -468,10 +475,13 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
|
||||
// These items live in the type namespace.
|
||||
ItemTy(..) => {
|
||||
let name_bindings =
|
||||
self.add_child(name, parent, ForbidDuplicateTypesAndModules, sp);
|
||||
let name_bindings = self.add_child(name,
|
||||
parent,
|
||||
ForbidDuplicateTypesAndModules,
|
||||
sp);
|
||||
|
||||
name_bindings.define_type(DefTy(self.ast_map.local_def_id(item.id), false), sp,
|
||||
name_bindings.define_type(DefTy(self.ast_map.local_def_id(item.id), false),
|
||||
sp,
|
||||
modifiers);
|
||||
|
||||
let parent_link = self.get_parent_link(parent, name);
|
||||
@ -485,8 +495,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
}
|
||||
|
||||
ItemEnum(ref enum_definition, _) => {
|
||||
let name_bindings =
|
||||
self.add_child(name, parent, ForbidDuplicateTypesAndModules, sp);
|
||||
let name_bindings = self.add_child(name,
|
||||
parent,
|
||||
ForbidDuplicateTypesAndModules,
|
||||
sp);
|
||||
|
||||
name_bindings.define_type(DefTy(self.ast_map.local_def_id(item.id), true),
|
||||
sp,
|
||||
@ -504,10 +516,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
|
||||
for variant in &(*enum_definition).variants {
|
||||
let item_def_id = self.ast_map.local_def_id(item.id);
|
||||
self.build_reduced_graph_for_variant(
|
||||
&**variant,
|
||||
item_def_id,
|
||||
&module);
|
||||
self.build_reduced_graph_for_variant(&**variant, item_def_id, &module);
|
||||
}
|
||||
parent.clone()
|
||||
}
|
||||
@ -522,20 +531,21 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
if let Some(child) = child {
|
||||
// check if theres a DefMod
|
||||
if let Some(DefMod(_)) = child.def_for_namespace(TypeNS) {
|
||||
self.session.span_warn(sp, &format!(
|
||||
"duplicate definition of {} `{}`. \
|
||||
Defining a module and a struct with \
|
||||
the same name will be disallowed \
|
||||
soon.",
|
||||
namespace_error_to_string(TypeError),
|
||||
name));
|
||||
self.session.span_warn(sp,
|
||||
&format!("duplicate definition of {} `{}`. \
|
||||
Defining a module and a struct \
|
||||
with the same name will be \
|
||||
disallowed soon.",
|
||||
namespace_error_to_string(TypeError),
|
||||
name));
|
||||
{
|
||||
let r = child.span_for_namespace(TypeNS);
|
||||
if let Some(sp) = r {
|
||||
self.session.span_note(sp,
|
||||
&format!("first definition of {} `{}` here",
|
||||
namespace_error_to_string(TypeError),
|
||||
name));
|
||||
self.session
|
||||
.span_note(sp,
|
||||
&format!("first definition of {} `{}` here",
|
||||
namespace_error_to_string(TypeError),
|
||||
name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -559,12 +569,15 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
}
|
||||
|
||||
// Record the def ID and fields of this struct.
|
||||
let named_fields = struct_def.fields().iter().filter_map(|f| {
|
||||
match f.node.kind {
|
||||
NamedField(name, _) => Some(name),
|
||||
UnnamedField(_) => None
|
||||
}
|
||||
}).collect();
|
||||
let named_fields = struct_def.fields()
|
||||
.iter()
|
||||
.filter_map(|f| {
|
||||
match f.node.kind {
|
||||
NamedField(name, _) => Some(name),
|
||||
UnnamedField(_) => None,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let item_def_id = self.ast_map.local_def_id(item.id);
|
||||
self.structs.insert(item_def_id, named_fields);
|
||||
|
||||
@ -575,8 +588,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
ItemImpl(..) => parent.clone(),
|
||||
|
||||
ItemTrait(_, _, _, ref items) => {
|
||||
let name_bindings =
|
||||
self.add_child(name, parent, ForbidDuplicateTypesAndModules, sp);
|
||||
let name_bindings = self.add_child(name,
|
||||
parent,
|
||||
ForbidDuplicateTypesAndModules,
|
||||
sp);
|
||||
|
||||
// Add all the items within to a new module.
|
||||
let parent_link = self.get_parent_link(parent, name);
|
||||
@ -593,9 +608,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
// Add the names of all the items to the trait info.
|
||||
for trait_item in items {
|
||||
let name_bindings = self.add_child(trait_item.name,
|
||||
&module_parent,
|
||||
ForbidDuplicateTypesAndValues,
|
||||
trait_item.span);
|
||||
&module_parent,
|
||||
ForbidDuplicateTypesAndValues,
|
||||
trait_item.span);
|
||||
|
||||
match trait_item.node {
|
||||
hir::ConstTraitItem(..) => {
|
||||
@ -642,19 +657,19 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
false
|
||||
};
|
||||
|
||||
let child = self.add_child(name, parent,
|
||||
ForbidDuplicateTypesAndValues,
|
||||
variant.span);
|
||||
let child = self.add_child(name, parent, ForbidDuplicateTypesAndValues, variant.span);
|
||||
// variants are always treated as importable to allow them to be glob
|
||||
// used
|
||||
child.define_value(DefVariant(item_id,
|
||||
self.ast_map.local_def_id(variant.node.data.id()),
|
||||
is_exported),
|
||||
variant.span, DefModifiers::PUBLIC | DefModifiers::IMPORTABLE);
|
||||
variant.span,
|
||||
DefModifiers::PUBLIC | DefModifiers::IMPORTABLE);
|
||||
child.define_type(DefVariant(item_id,
|
||||
self.ast_map.local_def_id(variant.node.data.id()),
|
||||
is_exported),
|
||||
variant.span, DefModifiers::PUBLIC | DefModifiers::IMPORTABLE);
|
||||
variant.span,
|
||||
DefModifiers::PUBLIC | DefModifiers::IMPORTABLE);
|
||||
}
|
||||
|
||||
/// Constructs the reduced graph for one foreign item.
|
||||
@ -668,9 +683,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
} else {
|
||||
DefModifiers::empty()
|
||||
} | DefModifiers::IMPORTABLE;
|
||||
let name_bindings =
|
||||
self.add_child(name, parent, ForbidDuplicateValues,
|
||||
foreign_item.span);
|
||||
let name_bindings = self.add_child(name, parent, ForbidDuplicateValues, foreign_item.span);
|
||||
|
||||
let def = match foreign_item.node {
|
||||
ForeignItemFn(..) => {
|
||||
@ -687,16 +700,15 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
if self.block_needs_anonymous_module(block) {
|
||||
let block_id = block.id;
|
||||
|
||||
debug!("(building reduced graph for block) creating a new \
|
||||
anonymous module for block {}",
|
||||
debug!("(building reduced graph for block) creating a new anonymous module for block \
|
||||
{}",
|
||||
block_id);
|
||||
|
||||
let new_module = Rc::new(Module::new(
|
||||
BlockParentLink(Rc::downgrade(parent), block_id),
|
||||
None,
|
||||
AnonymousModuleKind,
|
||||
false,
|
||||
false));
|
||||
let new_module = Rc::new(Module::new(BlockParentLink(Rc::downgrade(parent), block_id),
|
||||
None,
|
||||
AnonymousModuleKind,
|
||||
false,
|
||||
false));
|
||||
parent.anonymous_children.borrow_mut().insert(block_id, new_module.clone());
|
||||
new_module
|
||||
} else {
|
||||
@ -711,18 +723,19 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
final_ident: &str,
|
||||
name: Name,
|
||||
new_parent: &Rc<Module>) {
|
||||
debug!("(building reduced graph for \
|
||||
external crate) building external def {}, priv {:?}",
|
||||
final_ident, vis);
|
||||
debug!("(building reduced graph for external crate) building external def {}, priv {:?}",
|
||||
final_ident,
|
||||
vis);
|
||||
let is_public = vis == hir::Public;
|
||||
let modifiers = if is_public {
|
||||
DefModifiers::PUBLIC
|
||||
} else {
|
||||
DefModifiers::empty()
|
||||
} | DefModifiers::IMPORTABLE;
|
||||
let is_exported = is_public && match new_parent.def_id.get() {
|
||||
let is_exported = is_public &&
|
||||
match new_parent.def_id.get() {
|
||||
None => true,
|
||||
Some(did) => self.external_exports.contains(&did)
|
||||
Some(did) => self.external_exports.contains(&did),
|
||||
};
|
||||
if is_exported {
|
||||
self.external_exports.insert(def.def_id());
|
||||
@ -731,140 +744,148 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
let kind = match def {
|
||||
DefTy(_, true) => EnumModuleKind,
|
||||
DefTy(_, false) | DefStruct(..) => TypeModuleKind,
|
||||
_ => NormalModuleKind
|
||||
_ => NormalModuleKind,
|
||||
};
|
||||
|
||||
match def {
|
||||
DefMod(def_id) | DefForeignMod(def_id) | DefStruct(def_id) |
|
||||
DefTy(def_id, _) => {
|
||||
let type_def = child_name_bindings.type_def.borrow().clone();
|
||||
match type_def {
|
||||
Some(TypeNsDef { module_def: Some(module_def), .. }) => {
|
||||
debug!("(building reduced graph for external crate) \
|
||||
already created module");
|
||||
module_def.def_id.set(Some(def_id));
|
||||
}
|
||||
Some(_) | None => {
|
||||
debug!("(building reduced graph for \
|
||||
external crate) building module \
|
||||
{} {}", final_ident, is_public);
|
||||
let parent_link = self.get_parent_link(new_parent, name);
|
||||
DefMod(def_id) |
|
||||
DefForeignMod(def_id) |
|
||||
DefStruct(def_id) |
|
||||
DefTy(def_id, _) => {
|
||||
let type_def = child_name_bindings.type_def.borrow().clone();
|
||||
match type_def {
|
||||
Some(TypeNsDef { module_def: Some(module_def), .. }) => {
|
||||
debug!("(building reduced graph for external crate) already created \
|
||||
module");
|
||||
module_def.def_id.set(Some(def_id));
|
||||
}
|
||||
Some(_) | None => {
|
||||
debug!("(building reduced graph for external crate) building module {} {}",
|
||||
final_ident,
|
||||
is_public);
|
||||
let parent_link = self.get_parent_link(new_parent, name);
|
||||
|
||||
child_name_bindings.define_module(parent_link,
|
||||
Some(def_id),
|
||||
kind,
|
||||
true,
|
||||
is_public,
|
||||
DUMMY_SP);
|
||||
}
|
||||
child_name_bindings.define_module(parent_link,
|
||||
Some(def_id),
|
||||
kind,
|
||||
true,
|
||||
is_public,
|
||||
DUMMY_SP);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
match def {
|
||||
DefMod(_) | DefForeignMod(_) => {}
|
||||
DefVariant(_, variant_id, is_struct) => {
|
||||
debug!("(building reduced graph for external crate) building \
|
||||
variant {}",
|
||||
final_ident);
|
||||
// variants are always treated as importable to allow them to be
|
||||
// glob used
|
||||
let modifiers = DefModifiers::PUBLIC | DefModifiers::IMPORTABLE;
|
||||
if is_struct {
|
||||
child_name_bindings.define_type(def, DUMMY_SP, modifiers);
|
||||
// Not adding fields for variants as they are not accessed with a self receiver
|
||||
self.structs.insert(variant_id, Vec::new());
|
||||
} else {
|
||||
child_name_bindings.define_value(def, DUMMY_SP, modifiers);
|
||||
}
|
||||
}
|
||||
DefFn(ctor_id, true) => {
|
||||
child_name_bindings.define_value(
|
||||
DefMod(_) | DefForeignMod(_) => {}
|
||||
DefVariant(_, variant_id, is_struct) => {
|
||||
debug!("(building reduced graph for external crate) building variant {}",
|
||||
final_ident);
|
||||
// variants are always treated as importable to allow them to be
|
||||
// glob used
|
||||
let modifiers = DefModifiers::PUBLIC | DefModifiers::IMPORTABLE;
|
||||
if is_struct {
|
||||
child_name_bindings.define_type(def, DUMMY_SP, modifiers);
|
||||
// Not adding fields for variants as they are not accessed with a self receiver
|
||||
self.structs.insert(variant_id, Vec::new());
|
||||
} else {
|
||||
child_name_bindings.define_value(def, DUMMY_SP, modifiers);
|
||||
}
|
||||
}
|
||||
DefFn(ctor_id, true) => {
|
||||
child_name_bindings.define_value(
|
||||
csearch::get_tuple_struct_definition_if_ctor(&self.session.cstore, ctor_id)
|
||||
.map_or(def, |_| DefStruct(ctor_id)), DUMMY_SP, modifiers);
|
||||
}
|
||||
DefFn(..) | DefStatic(..) | DefConst(..) | DefAssociatedConst(..) |
|
||||
DefMethod(..) => {
|
||||
debug!("(building reduced graph for external \
|
||||
crate) building value (fn/static) {}", final_ident);
|
||||
// impl methods have already been defined with the correct importability modifier
|
||||
let mut modifiers = match *child_name_bindings.value_def.borrow() {
|
||||
Some(ref def) => (modifiers & !DefModifiers::IMPORTABLE) |
|
||||
(def.modifiers & DefModifiers::IMPORTABLE),
|
||||
None => modifiers
|
||||
};
|
||||
if new_parent.kind.get() != NormalModuleKind {
|
||||
modifiers = modifiers & !DefModifiers::IMPORTABLE;
|
||||
}
|
||||
child_name_bindings.define_value(def, DUMMY_SP, modifiers);
|
||||
}
|
||||
DefTrait(def_id) => {
|
||||
debug!("(building reduced graph for external \
|
||||
crate) building type {}", final_ident);
|
||||
|
||||
// If this is a trait, add all the trait item names to the trait
|
||||
// info.
|
||||
|
||||
let trait_item_def_ids =
|
||||
csearch::get_trait_item_def_ids(&self.session.cstore, def_id);
|
||||
for trait_item_def in &trait_item_def_ids {
|
||||
let trait_item_name = csearch::get_trait_name(&self.session.cstore,
|
||||
trait_item_def.def_id());
|
||||
|
||||
debug!("(building reduced graph for external crate) ... \
|
||||
adding trait item '{}'",
|
||||
trait_item_name);
|
||||
|
||||
self.trait_item_map.insert((trait_item_name, def_id),
|
||||
trait_item_def.def_id());
|
||||
|
||||
if is_exported {
|
||||
self.external_exports.insert(trait_item_def.def_id());
|
||||
}
|
||||
}
|
||||
|
||||
child_name_bindings.define_type(def, DUMMY_SP, modifiers);
|
||||
|
||||
// Define a module if necessary.
|
||||
let parent_link = self.get_parent_link(new_parent, name);
|
||||
child_name_bindings.set_module_kind(parent_link,
|
||||
Some(def_id),
|
||||
TraitModuleKind,
|
||||
true,
|
||||
is_public,
|
||||
DUMMY_SP)
|
||||
}
|
||||
DefTy(..) | DefAssociatedTy(..) => {
|
||||
debug!("(building reduced graph for external \
|
||||
crate) building type {}", final_ident);
|
||||
|
||||
let modifiers = match new_parent.kind.get() {
|
||||
NormalModuleKind => modifiers,
|
||||
_ => modifiers & !DefModifiers::IMPORTABLE
|
||||
};
|
||||
|
||||
child_name_bindings.define_type(def, DUMMY_SP, modifiers);
|
||||
}
|
||||
DefStruct(def_id) => {
|
||||
debug!("(building reduced graph for external \
|
||||
crate) building type and value for {}",
|
||||
final_ident);
|
||||
child_name_bindings.define_type(def, DUMMY_SP, modifiers);
|
||||
let fields = csearch::get_struct_field_names(&self.session.cstore, def_id);
|
||||
|
||||
if fields.is_empty() {
|
||||
DefFn(..) |
|
||||
DefStatic(..) |
|
||||
DefConst(..) |
|
||||
DefAssociatedConst(..) |
|
||||
DefMethod(..) => {
|
||||
debug!("(building reduced graph for external crate) building value (fn/static) {}",
|
||||
final_ident);
|
||||
// impl methods have already been defined with the correct importability
|
||||
// modifier
|
||||
let mut modifiers = match *child_name_bindings.value_def.borrow() {
|
||||
Some(ref def) => (modifiers & !DefModifiers::IMPORTABLE) |
|
||||
(def.modifiers & DefModifiers::IMPORTABLE),
|
||||
None => modifiers,
|
||||
};
|
||||
if new_parent.kind.get() != NormalModuleKind {
|
||||
modifiers = modifiers & !DefModifiers::IMPORTABLE;
|
||||
}
|
||||
child_name_bindings.define_value(def, DUMMY_SP, modifiers);
|
||||
}
|
||||
DefTrait(def_id) => {
|
||||
debug!("(building reduced graph for external crate) building type {}",
|
||||
final_ident);
|
||||
|
||||
// Record the def ID and fields of this struct.
|
||||
self.structs.insert(def_id, fields);
|
||||
}
|
||||
DefLocal(..) | DefPrimTy(..) | DefTyParam(..) |
|
||||
DefUse(..) | DefUpvar(..) |
|
||||
DefLabel(..) | DefSelfTy(..) => {
|
||||
panic!("didn't expect `{:?}`", def);
|
||||
}
|
||||
// If this is a trait, add all the trait item names to the trait
|
||||
// info.
|
||||
|
||||
let trait_item_def_ids = csearch::get_trait_item_def_ids(&self.session.cstore,
|
||||
def_id);
|
||||
for trait_item_def in &trait_item_def_ids {
|
||||
let trait_item_name = csearch::get_trait_name(&self.session.cstore,
|
||||
trait_item_def.def_id());
|
||||
|
||||
debug!("(building reduced graph for external crate) ... adding trait item \
|
||||
'{}'",
|
||||
trait_item_name);
|
||||
|
||||
self.trait_item_map.insert((trait_item_name, def_id), trait_item_def.def_id());
|
||||
|
||||
if is_exported {
|
||||
self.external_exports.insert(trait_item_def.def_id());
|
||||
}
|
||||
}
|
||||
|
||||
child_name_bindings.define_type(def, DUMMY_SP, modifiers);
|
||||
|
||||
// Define a module if necessary.
|
||||
let parent_link = self.get_parent_link(new_parent, name);
|
||||
child_name_bindings.set_module_kind(parent_link,
|
||||
Some(def_id),
|
||||
TraitModuleKind,
|
||||
true,
|
||||
is_public,
|
||||
DUMMY_SP)
|
||||
}
|
||||
DefTy(..) | DefAssociatedTy(..) => {
|
||||
debug!("(building reduced graph for external crate) building type {}",
|
||||
final_ident);
|
||||
|
||||
let modifiers = match new_parent.kind.get() {
|
||||
NormalModuleKind => modifiers,
|
||||
_ => modifiers & !DefModifiers::IMPORTABLE,
|
||||
};
|
||||
|
||||
child_name_bindings.define_type(def, DUMMY_SP, modifiers);
|
||||
}
|
||||
DefStruct(def_id) => {
|
||||
debug!("(building reduced graph for external crate) building type and value for \
|
||||
{}",
|
||||
final_ident);
|
||||
child_name_bindings.define_type(def, DUMMY_SP, modifiers);
|
||||
let fields = csearch::get_struct_field_names(&self.session.cstore, def_id);
|
||||
|
||||
if fields.is_empty() {
|
||||
child_name_bindings.define_value(def, DUMMY_SP, modifiers);
|
||||
}
|
||||
|
||||
// Record the def ID and fields of this struct.
|
||||
self.structs.insert(def_id, fields);
|
||||
}
|
||||
DefLocal(..) |
|
||||
DefPrimTy(..) |
|
||||
DefTyParam(..) |
|
||||
DefUse(..) |
|
||||
DefUpvar(..) |
|
||||
DefLabel(..) |
|
||||
DefSelfTy(..) => {
|
||||
panic!("didn't expect `{:?}`", def);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -894,11 +915,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
});
|
||||
}
|
||||
_ => {
|
||||
let child_name_bindings =
|
||||
self.add_child(name,
|
||||
root,
|
||||
OverwriteDuplicates,
|
||||
DUMMY_SP);
|
||||
let child_name_bindings = self.add_child(name,
|
||||
root,
|
||||
OverwriteDuplicates,
|
||||
DUMMY_SP);
|
||||
|
||||
self.handle_external_def(def,
|
||||
def_visibility,
|
||||
@ -910,12 +930,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
}
|
||||
}
|
||||
DlImpl(_) => {
|
||||
debug!("(building reduced graph for external crate) \
|
||||
ignoring impl");
|
||||
debug!("(building reduced graph for external crate) ignoring impl");
|
||||
}
|
||||
DlField => {
|
||||
debug!("(building reduced graph for external crate) \
|
||||
ignoring field");
|
||||
debug!("(building reduced graph for external crate) ignoring field");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -928,7 +946,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
let def_id = match module.def_id.get() {
|
||||
None => {
|
||||
debug!("(populating external module) ... no def ID!");
|
||||
return
|
||||
return;
|
||||
}
|
||||
Some(def_id) => def_id,
|
||||
};
|
||||
@ -936,13 +954,13 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
csearch::each_child_of_item(&self.session.cstore,
|
||||
def_id,
|
||||
|def_like, child_name, visibility| {
|
||||
debug!("(populating external module) ... found ident: {}",
|
||||
child_name);
|
||||
self.build_reduced_graph_for_external_crate_def(module,
|
||||
def_like,
|
||||
child_name,
|
||||
visibility)
|
||||
});
|
||||
debug!("(populating external module) ... found ident: {}",
|
||||
child_name);
|
||||
self.build_reduced_graph_for_external_crate_def(module,
|
||||
def_like,
|
||||
child_name,
|
||||
visibility)
|
||||
});
|
||||
module.populated.set(true)
|
||||
}
|
||||
|
||||
@ -977,12 +995,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
id: NodeId,
|
||||
is_public: bool,
|
||||
shadowable: Shadowable) {
|
||||
module_.imports.borrow_mut().push(ImportDirective::new(module_path,
|
||||
subclass,
|
||||
span,
|
||||
id,
|
||||
is_public,
|
||||
shadowable));
|
||||
module_.imports
|
||||
.borrow_mut()
|
||||
.push(ImportDirective::new(module_path, subclass, span, id, is_public, shadowable));
|
||||
self.unresolved_imports += 1;
|
||||
|
||||
if is_public {
|
||||
@ -1030,9 +1045,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
struct BuildReducedGraphVisitor<'a, 'b:'a, 'tcx:'b> {
|
||||
struct BuildReducedGraphVisitor<'a, 'b: 'a, 'tcx: 'b> {
|
||||
builder: GraphBuilder<'a, 'b, 'tcx>,
|
||||
parent: Rc<Module>
|
||||
parent: Rc<Module>,
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'v, 'tcx> Visitor<'v> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
@ -1056,13 +1071,9 @@ impl<'a, 'b, 'v, 'tcx> Visitor<'v> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
}
|
||||
|
||||
pub fn build_reduced_graph(resolver: &mut Resolver, krate: &hir::Crate) {
|
||||
GraphBuilder {
|
||||
resolver: resolver
|
||||
}.build_reduced_graph(krate);
|
||||
GraphBuilder { resolver: resolver }.build_reduced_graph(krate);
|
||||
}
|
||||
|
||||
pub fn populate_module_if_necessary(resolver: &mut Resolver, module: &Rc<Module>) {
|
||||
GraphBuilder {
|
||||
resolver: resolver
|
||||
}.populate_module_if_necessary(module);
|
||||
GraphBuilder { resolver: resolver }.populate_module_if_necessary(module);
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ use rustc_front::hir;
|
||||
use rustc_front::hir::{ViewPathGlob, ViewPathList, ViewPathSimple};
|
||||
use rustc_front::visit::{self, Visitor};
|
||||
|
||||
struct UnusedImportCheckVisitor<'a, 'b:'a, 'tcx:'b> {
|
||||
resolver: &'a mut Resolver<'b, 'tcx>
|
||||
struct UnusedImportCheckVisitor<'a, 'b: 'a, 'tcx: 'b> {
|
||||
resolver: &'a mut Resolver<'b, 'tcx>,
|
||||
}
|
||||
|
||||
// Deref and DerefMut impls allow treating UnusedImportCheckVisitor as Resolver.
|
||||
@ -51,16 +51,16 @@ impl<'a, 'b, 'tcx:'b> DerefMut for UnusedImportCheckVisitor<'a, 'b, 'tcx> {
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'tcx> UnusedImportCheckVisitor<'a, 'b, 'tcx> {
|
||||
// We have information about whether `use` (import) directives are actually used now.
|
||||
// If an import is not used at all, we signal a lint error. If an import is only used
|
||||
// for a single namespace, we remove the other namespace from the recorded privacy
|
||||
// information. That means in privacy.rs, we will only check imports and namespaces
|
||||
// which are used. In particular, this means that if an import could name either a
|
||||
// public or private item, we will check the correct thing, dependent on how the import
|
||||
// is used.
|
||||
// We have information about whether `use` (import) directives are actually
|
||||
// used now. If an import is not used at all, we signal a lint error. If an
|
||||
// import is only used for a single namespace, we remove the other namespace
|
||||
// from the recorded privacy information. That means in privacy.rs, we will
|
||||
// only check imports and namespaces which are used. In particular, this
|
||||
// means that if an import could name either a public or private item, we
|
||||
// will check the correct thing, dependent on how the import is used.
|
||||
fn finalize_import(&mut self, id: ast::NodeId, span: Span) {
|
||||
debug!("finalizing import uses for {:?}",
|
||||
self.session.codemap().span_to_snippet(span));
|
||||
self.session.codemap().span_to_snippet(span));
|
||||
|
||||
if !self.used_imports.contains(&(id, TypeNS)) &&
|
||||
!self.used_imports.contains(&(id, ValueNS)) {
|
||||
@ -99,14 +99,14 @@ impl<'a, 'b, 'tcx> UnusedImportCheckVisitor<'a, 'b, 'tcx> {
|
||||
// we might have two LastPrivates pointing at the same thing. There is no point
|
||||
// checking both, so lets not check the value one.
|
||||
(Some(DependsOn(def_v)), Some(DependsOn(def_t))) if def_v == def_t => v_used = Unused,
|
||||
_ => {},
|
||||
_ => {}
|
||||
}
|
||||
|
||||
path_res.last_private = LastImport {
|
||||
value_priv: v_priv,
|
||||
value_used: v_used,
|
||||
type_priv: t_priv,
|
||||
type_used: t_used
|
||||
type_used: t_used,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -132,7 +132,7 @@ impl<'a, 'b, 'v, 'tcx> Visitor<'v> for UnusedImportCheckVisitor<'a, 'b, 'tcx> {
|
||||
"unused extern crate".to_string());
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
hir::ItemUse(ref p) => {
|
||||
match p.node {
|
||||
ViewPathSimple(_, _) => {
|
||||
|
@ -10,9 +10,9 @@
|
||||
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
// Error messages for EXXXX errors.
|
||||
// Each message should start and end with a new line, and be wrapped to 80 characters.
|
||||
// In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
|
||||
// Error messages for EXXXX errors. Each message should start and end with a
|
||||
// new line, and be wrapped to 80 characters. In vim you can `:set tw=80` and
|
||||
// use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
|
||||
register_long_diagnostics! {
|
||||
|
||||
E0154: r##"
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -30,8 +30,8 @@ use syntax::ast;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::rc::Rc;
|
||||
|
||||
struct ExportRecorder<'a, 'b:'a, 'tcx:'b> {
|
||||
resolver: &'a mut Resolver<'b, 'tcx>
|
||||
struct ExportRecorder<'a, 'b: 'a, 'tcx: 'b> {
|
||||
resolver: &'a mut Resolver<'b, 'tcx>,
|
||||
}
|
||||
|
||||
// Deref and DerefMut impls allow treating ExportRecorder as Resolver.
|
||||
@ -50,28 +50,26 @@ impl<'a, 'b, 'tcx:'b> DerefMut for ExportRecorder<'a, 'b, 'tcx> {
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'tcx> ExportRecorder<'a, 'b, 'tcx> {
|
||||
fn record_exports_for_module_subtree(&mut self,
|
||||
module_: Rc<Module>) {
|
||||
fn record_exports_for_module_subtree(&mut self, module_: Rc<Module>) {
|
||||
// If this isn't a local krate, then bail out. We don't need to record
|
||||
// exports for nonlocal crates.
|
||||
|
||||
match module_.def_id.get() {
|
||||
Some(def_id) if def_id.is_local() => {
|
||||
// OK. Continue.
|
||||
debug!("(recording exports for module subtree) recording \
|
||||
exports for local module `{}`",
|
||||
debug!("(recording exports for module subtree) recording exports for local \
|
||||
module `{}`",
|
||||
module_to_string(&*module_));
|
||||
}
|
||||
None => {
|
||||
// Record exports for the root module.
|
||||
debug!("(recording exports for module subtree) recording \
|
||||
exports for root module `{}`",
|
||||
debug!("(recording exports for module subtree) recording exports for root module \
|
||||
`{}`",
|
||||
module_to_string(&*module_));
|
||||
}
|
||||
Some(_) => {
|
||||
// Bail out.
|
||||
debug!("(recording exports for module subtree) not recording \
|
||||
exports for `{}`",
|
||||
debug!("(recording exports for module subtree) not recording exports for `{}`",
|
||||
module_to_string(&*module_));
|
||||
return;
|
||||
}
|
||||
@ -118,10 +116,11 @@ impl<'a, 'b, 'tcx> ExportRecorder<'a, 'b, 'tcx> {
|
||||
match namebindings.def_for_namespace(ns) {
|
||||
Some(d) => {
|
||||
debug!("(computing exports) YES: export '{}' => {:?}",
|
||||
name, d.def_id());
|
||||
name,
|
||||
d.def_id());
|
||||
exports.push(Export {
|
||||
name: name,
|
||||
def_id: d.def_id()
|
||||
def_id: d.def_id(),
|
||||
});
|
||||
}
|
||||
d_opt => {
|
||||
@ -130,25 +129,19 @@ impl<'a, 'b, 'tcx> ExportRecorder<'a, 'b, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_exports_for_module(&mut self,
|
||||
exports: &mut Vec<Export>,
|
||||
module_: &Module) {
|
||||
fn add_exports_for_module(&mut self, exports: &mut Vec<Export>, module_: &Module) {
|
||||
for (name, import_resolution) in module_.import_resolutions.borrow().iter() {
|
||||
if !import_resolution.is_public {
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
let xs = [TypeNS, ValueNS];
|
||||
for &ns in &xs {
|
||||
match import_resolution.target_for_namespace(ns) {
|
||||
Some(target) => {
|
||||
debug!("(computing exports) maybe export '{}'",
|
||||
name);
|
||||
self.add_exports_of_namebindings(exports,
|
||||
*name,
|
||||
&*target.bindings,
|
||||
ns)
|
||||
debug!("(computing exports) maybe export '{}'", name);
|
||||
self.add_exports_of_namebindings(exports, *name, &*target.bindings, ns)
|
||||
}
|
||||
_ => ()
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,14 +42,14 @@ use std::rc::Rc;
|
||||
#[derive(Copy, Clone,Debug)]
|
||||
pub enum ImportDirectiveSubclass {
|
||||
SingleImport(Name /* target */, Name /* source */),
|
||||
GlobImport
|
||||
GlobImport,
|
||||
}
|
||||
|
||||
/// Whether an import can be shadowed by another import.
|
||||
#[derive(Debug,PartialEq,Clone,Copy)]
|
||||
pub enum Shadowable {
|
||||
Always,
|
||||
Never
|
||||
Never,
|
||||
}
|
||||
|
||||
/// One import directive.
|
||||
@ -64,13 +64,13 @@ pub struct ImportDirective {
|
||||
}
|
||||
|
||||
impl ImportDirective {
|
||||
pub fn new(module_path: Vec<Name> ,
|
||||
subclass: ImportDirectiveSubclass,
|
||||
span: Span,
|
||||
id: NodeId,
|
||||
is_public: bool,
|
||||
shadowable: Shadowable)
|
||||
-> ImportDirective {
|
||||
pub fn new(module_path: Vec<Name>,
|
||||
subclass: ImportDirectiveSubclass,
|
||||
span: Span,
|
||||
id: NodeId,
|
||||
is_public: bool,
|
||||
shadowable: Shadowable)
|
||||
-> ImportDirective {
|
||||
ImportDirective {
|
||||
module_path: module_path,
|
||||
subclass: subclass,
|
||||
@ -92,9 +92,9 @@ pub struct Target {
|
||||
|
||||
impl Target {
|
||||
pub fn new(target_module: Rc<Module>,
|
||||
bindings: Rc<NameBindings>,
|
||||
shadowable: Shadowable)
|
||||
-> Target {
|
||||
bindings: Rc<NameBindings>,
|
||||
shadowable: Shadowable)
|
||||
-> Target {
|
||||
Target {
|
||||
target_module: target_module,
|
||||
bindings: bindings,
|
||||
@ -144,17 +144,16 @@ impl ImportResolution {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn target_for_namespace(&self, namespace: Namespace)
|
||||
-> Option<Target> {
|
||||
pub fn target_for_namespace(&self, namespace: Namespace) -> Option<Target> {
|
||||
match namespace {
|
||||
TypeNS => self.type_target.clone(),
|
||||
TypeNS => self.type_target.clone(),
|
||||
ValueNS => self.value_target.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn id(&self, namespace: Namespace) -> NodeId {
|
||||
match namespace {
|
||||
TypeNS => self.type_id,
|
||||
TypeNS => self.type_id,
|
||||
ValueNS => self.value_id,
|
||||
}
|
||||
}
|
||||
@ -168,12 +167,9 @@ impl ImportResolution {
|
||||
target.unwrap().shadowable
|
||||
}
|
||||
|
||||
pub fn set_target_and_id(&mut self,
|
||||
namespace: Namespace,
|
||||
target: Option<Target>,
|
||||
id: NodeId) {
|
||||
pub fn set_target_and_id(&mut self, namespace: Namespace, target: Option<Target>, id: NodeId) {
|
||||
match namespace {
|
||||
TypeNS => {
|
||||
TypeNS => {
|
||||
self.type_target = target;
|
||||
self.type_id = id;
|
||||
}
|
||||
@ -191,8 +187,8 @@ struct ImportResolvingError {
|
||||
help: String,
|
||||
}
|
||||
|
||||
struct ImportResolver<'a, 'b:'a, 'tcx:'b> {
|
||||
resolver: &'a mut Resolver<'b, 'tcx>
|
||||
struct ImportResolver<'a, 'b: 'a, 'tcx: 'b> {
|
||||
resolver: &'a mut Resolver<'b, 'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
@ -211,7 +207,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
let mut prev_unresolved_imports = 0;
|
||||
loop {
|
||||
debug!("(resolving imports) iteration {}, {} imports left",
|
||||
i, self.resolver.unresolved_imports);
|
||||
i,
|
||||
self.resolver.unresolved_imports);
|
||||
|
||||
let module_root = self.resolver.graph_root.get_module();
|
||||
let errors = self.resolve_imports_for_module_subtree(module_root.clone());
|
||||
@ -246,7 +243,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
|
||||
/// Attempts to resolve imports for the given module and all of its
|
||||
/// submodules.
|
||||
fn resolve_imports_for_module_subtree(&mut self, module_: Rc<Module>)
|
||||
fn resolve_imports_for_module_subtree(&mut self,
|
||||
module_: Rc<Module>)
|
||||
-> Vec<ImportResolvingError> {
|
||||
let mut errors = Vec::new();
|
||||
debug!("(resolving imports for module subtree) resolving {}",
|
||||
@ -279,8 +277,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
let mut errors = Vec::new();
|
||||
|
||||
if module.all_imports_resolved() {
|
||||
debug!("(resolving imports for module) all imports resolved for \
|
||||
{}",
|
||||
debug!("(resolving imports for module) all imports resolved for {}",
|
||||
module_to_string(&*module));
|
||||
return errors;
|
||||
}
|
||||
@ -290,22 +287,19 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
let mut indeterminate_imports = Vec::new();
|
||||
while module.resolved_import_count.get() + indeterminate_imports.len() < import_count {
|
||||
let import_index = module.resolved_import_count.get();
|
||||
match self.resolve_import_for_module(module.clone(),
|
||||
&imports[import_index]) {
|
||||
match self.resolve_import_for_module(module.clone(), &imports[import_index]) {
|
||||
ResolveResult::Failed(err) => {
|
||||
let import_directive = &imports[import_index];
|
||||
let (span, help) = match err {
|
||||
Some((span, msg)) => (span, format!(". {}", msg)),
|
||||
None => (import_directive.span, String::new())
|
||||
None => (import_directive.span, String::new()),
|
||||
};
|
||||
errors.push(ImportResolvingError {
|
||||
span: span,
|
||||
path: import_path_to_string(
|
||||
&import_directive.module_path,
|
||||
import_directive.subclass
|
||||
),
|
||||
help: help
|
||||
});
|
||||
span: span,
|
||||
path: import_path_to_string(&import_directive.module_path,
|
||||
import_directive.subclass),
|
||||
help: help,
|
||||
});
|
||||
}
|
||||
ResolveResult::Indeterminate => {}
|
||||
ResolveResult::Success(()) => {
|
||||
@ -354,7 +348,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
ResolveResult::Failed(err) => {
|
||||
resolution_result = ResolveResult::Failed(err);
|
||||
None
|
||||
},
|
||||
}
|
||||
ResolveResult::Indeterminate => {
|
||||
resolution_result = ResolveResult::Indeterminate;
|
||||
None
|
||||
@ -371,20 +365,18 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
|
||||
match import_directive.subclass {
|
||||
SingleImport(target, source) => {
|
||||
resolution_result =
|
||||
self.resolve_single_import(&module_,
|
||||
containing_module,
|
||||
target,
|
||||
source,
|
||||
import_directive,
|
||||
lp);
|
||||
resolution_result = self.resolve_single_import(&module_,
|
||||
containing_module,
|
||||
target,
|
||||
source,
|
||||
import_directive,
|
||||
lp);
|
||||
}
|
||||
GlobImport => {
|
||||
resolution_result =
|
||||
self.resolve_glob_import(&module_,
|
||||
containing_module,
|
||||
import_directive,
|
||||
lp);
|
||||
resolution_result = self.resolve_glob_import(&module_,
|
||||
containing_module,
|
||||
import_directive,
|
||||
lp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -433,8 +425,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
directive: &ImportDirective,
|
||||
lp: LastPrivate)
|
||||
-> ResolveResult<()> {
|
||||
debug!("(resolving single import) resolving `{}` = `{}::{}` from \
|
||||
`{}` id {}, last private {:?}",
|
||||
debug!("(resolving single import) resolving `{}` = `{}::{}` from `{}` id {}, last \
|
||||
private {:?}",
|
||||
target,
|
||||
module_to_string(&*target_module),
|
||||
source,
|
||||
@ -445,9 +437,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
let lp = match lp {
|
||||
LastMod(lp) => lp,
|
||||
LastImport {..} => {
|
||||
self.resolver.session
|
||||
.span_bug(directive.span,
|
||||
"not expecting Import here, must be LastMod")
|
||||
self.resolver
|
||||
.session
|
||||
.span_bug(directive.span, "not expecting Import here, must be LastMod")
|
||||
}
|
||||
};
|
||||
|
||||
@ -472,11 +464,10 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
value_result = BoundResult(target_module.clone(),
|
||||
(*child_name_bindings).clone());
|
||||
if directive.is_public && !child_name_bindings.is_public(ValueNS) {
|
||||
let msg = format!("`{}` is private, and cannot be reexported",
|
||||
source);
|
||||
let note_msg =
|
||||
format!("Consider marking `{}` as `pub` in the imported module",
|
||||
source);
|
||||
let msg = format!("`{}` is private, and cannot be reexported", source);
|
||||
let note_msg = format!("Consider marking `{}` as `pub` in the imported \
|
||||
module",
|
||||
source);
|
||||
span_err!(self.resolver.session, directive.span, E0364, "{}", &msg);
|
||||
self.resolver.session.span_note(directive.span, ¬e_msg);
|
||||
pub_err = true;
|
||||
@ -487,8 +478,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
type_result = BoundResult(target_module.clone(),
|
||||
(*child_name_bindings).clone());
|
||||
if !pub_err && directive.is_public && !child_name_bindings.is_public(TypeNS) {
|
||||
let msg = format!("`{}` is private, and cannot be reexported",
|
||||
source);
|
||||
let msg = format!("`{}` is private, and cannot be reexported", source);
|
||||
let note_msg = format!("Consider declaring module `{}` as a `pub mod`",
|
||||
source);
|
||||
span_err!(self.resolver.session, directive.span, E0365, "{}", &msg);
|
||||
@ -510,8 +500,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
// able to resolve this import.
|
||||
|
||||
if target_module.pub_glob_count.get() > 0 {
|
||||
debug!("(resolving single import) unresolved pub glob; \
|
||||
bailing out");
|
||||
debug!("(resolving single import) unresolved pub glob; bailing out");
|
||||
return ResolveResult::Indeterminate;
|
||||
}
|
||||
|
||||
@ -531,14 +520,13 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
type_result = UnboundResult;
|
||||
}
|
||||
}
|
||||
Some(import_resolution)
|
||||
if import_resolution.outstanding_references == 0 => {
|
||||
Some(import_resolution) if import_resolution.outstanding_references == 0 => {
|
||||
|
||||
fn get_binding(this: &mut Resolver,
|
||||
import_resolution: &ImportResolution,
|
||||
namespace: Namespace,
|
||||
source: Name)
|
||||
-> NamespaceResult {
|
||||
-> NamespaceResult {
|
||||
|
||||
// Import resolutions must be declared with "pub"
|
||||
// in order to be exported.
|
||||
@ -555,8 +543,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
bindings,
|
||||
shadowable: _
|
||||
}) => {
|
||||
debug!("(resolving single import) found \
|
||||
import in ns {:?}", namespace);
|
||||
debug!("(resolving single import) found import in ns {:?}",
|
||||
namespace);
|
||||
let id = import_resolution.id(namespace);
|
||||
// track used imports and extern crates as well
|
||||
this.used_imports.insert((id, namespace));
|
||||
@ -564,7 +552,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
match target_module.def_id.get() {
|
||||
Some(DefId{krate: kid, ..}) => {
|
||||
this.used_crates.insert(kid);
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
return BoundResult(target_module, bindings);
|
||||
@ -603,8 +591,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
// In this case we continue as if we resolved the import and let the
|
||||
// check_for_conflicts_between_imports_and_items call below handle
|
||||
// the conflict
|
||||
match (module_.def_id.get(), target_module.def_id.get()) {
|
||||
(Some(id1), Some(id2)) if id1 == id2 => {
|
||||
match (module_.def_id.get(), target_module.def_id.get()) {
|
||||
(Some(id1), Some(id2)) if id1 == id2 => {
|
||||
if value_result.is_unknown() {
|
||||
value_result = UnboundResult;
|
||||
}
|
||||
@ -612,10 +600,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
type_result = UnboundResult;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
_ => {
|
||||
// The import is unresolved. Bail out.
|
||||
debug!("(resolving single import) unresolved import; \
|
||||
bailing out");
|
||||
debug!("(resolving single import) unresolved import; bailing out");
|
||||
return ResolveResult::Indeterminate;
|
||||
}
|
||||
}
|
||||
@ -668,17 +655,15 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
debug!("(resolving single import) found {:?} target: {:?}",
|
||||
namespace_name,
|
||||
name_bindings.def_for_namespace(namespace));
|
||||
self.check_for_conflicting_import(
|
||||
&import_resolution,
|
||||
directive.span,
|
||||
target,
|
||||
namespace);
|
||||
self.check_for_conflicting_import(&import_resolution,
|
||||
directive.span,
|
||||
target,
|
||||
namespace);
|
||||
|
||||
self.check_that_import_is_importable(
|
||||
&**name_bindings,
|
||||
directive.span,
|
||||
target,
|
||||
namespace);
|
||||
self.check_that_import_is_importable(&**name_bindings,
|
||||
directive.span,
|
||||
target,
|
||||
namespace);
|
||||
|
||||
let target = Some(Target::new(target_module.clone(),
|
||||
name_bindings.clone(),
|
||||
@ -687,7 +672,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
import_resolution.is_public = directive.is_public;
|
||||
*used_public = name_bindings.defined_in_public_namespace(namespace);
|
||||
}
|
||||
UnboundResult => { /* Continue. */ }
|
||||
UnboundResult => {
|
||||
// Continue.
|
||||
}
|
||||
UnknownResult => {
|
||||
panic!("{:?} result should be known at this point", namespace_name);
|
||||
}
|
||||
@ -697,11 +684,10 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
check_and_write_import(TypeNS, &type_result, &mut type_used_public);
|
||||
}
|
||||
|
||||
self.check_for_conflicts_between_imports_and_items(
|
||||
module_,
|
||||
import_resolution,
|
||||
directive.span,
|
||||
target);
|
||||
self.check_for_conflicts_between_imports_and_items(module_,
|
||||
import_resolution,
|
||||
directive.span,
|
||||
target);
|
||||
|
||||
if value_result.is_unbound() && type_result.is_unbound() {
|
||||
let msg = format!("There is no `{}` in `{}`",
|
||||
@ -720,33 +706,45 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
// purposes it's good enough to just favor one over the other.
|
||||
let value_def_and_priv = import_resolution.value_target.as_ref().map(|target| {
|
||||
let def = target.bindings.def_for_namespace(ValueNS).unwrap();
|
||||
(def, if value_used_public { lp } else { DependsOn(def.def_id()) })
|
||||
(def,
|
||||
if value_used_public {
|
||||
lp
|
||||
} else {
|
||||
DependsOn(def.def_id())
|
||||
})
|
||||
});
|
||||
let type_def_and_priv = import_resolution.type_target.as_ref().map(|target| {
|
||||
let def = target.bindings.def_for_namespace(TypeNS).unwrap();
|
||||
(def, if type_used_public { lp } else { DependsOn(def.def_id()) })
|
||||
(def,
|
||||
if type_used_public {
|
||||
lp
|
||||
} else {
|
||||
DependsOn(def.def_id())
|
||||
})
|
||||
});
|
||||
|
||||
let import_lp = LastImport {
|
||||
value_priv: value_def_and_priv.map(|(_, p)| p),
|
||||
value_used: Used,
|
||||
type_priv: type_def_and_priv.map(|(_, p)| p),
|
||||
type_used: Used
|
||||
type_used: Used,
|
||||
};
|
||||
|
||||
if let Some((def, _)) = value_def_and_priv {
|
||||
self.resolver.def_map.borrow_mut().insert(directive.id, PathResolution {
|
||||
base_def: def,
|
||||
last_private: import_lp,
|
||||
depth: 0
|
||||
});
|
||||
self.resolver.def_map.borrow_mut().insert(directive.id,
|
||||
PathResolution {
|
||||
base_def: def,
|
||||
last_private: import_lp,
|
||||
depth: 0,
|
||||
});
|
||||
}
|
||||
if let Some((def, _)) = type_def_and_priv {
|
||||
self.resolver.def_map.borrow_mut().insert(directive.id, PathResolution {
|
||||
base_def: def,
|
||||
last_private: import_lp,
|
||||
depth: 0
|
||||
});
|
||||
self.resolver.def_map.borrow_mut().insert(directive.id,
|
||||
PathResolution {
|
||||
base_def: def,
|
||||
last_private: import_lp,
|
||||
depth: 0,
|
||||
});
|
||||
}
|
||||
|
||||
debug!("(resolving single import) successfully resolved import");
|
||||
@ -774,8 +772,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
// We must bail out if the node has unresolved imports of any kind
|
||||
// (including globs).
|
||||
if (*target_module).pub_count.get() > 0 {
|
||||
debug!("(resolving glob import) target module has unresolved \
|
||||
pub imports; bailing out");
|
||||
debug!("(resolving glob import) target module has unresolved pub imports; bailing out");
|
||||
return ResolveResult::Indeterminate;
|
||||
}
|
||||
|
||||
@ -787,21 +784,18 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
// This means we are trying to glob import a module into itself,
|
||||
// and it is a no-go
|
||||
debug!("(resolving glob imports) target module is current module; giving up");
|
||||
return ResolveResult::Failed(Some((
|
||||
import_directive.span,
|
||||
"Cannot glob-import a module into itself.".into()
|
||||
)));
|
||||
return ResolveResult::Failed(Some((import_directive.span,
|
||||
"Cannot glob-import a module into itself.".into())));
|
||||
}
|
||||
|
||||
for (name, target_import_resolution) in import_resolutions.iter() {
|
||||
debug!("(resolving glob import) writing module resolution \
|
||||
{} into `{}`",
|
||||
debug!("(resolving glob import) writing module resolution {} into `{}`",
|
||||
*name,
|
||||
module_to_string(module_));
|
||||
|
||||
if !target_import_resolution.is_public {
|
||||
debug!("(resolving glob import) nevermind, just kidding");
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
|
||||
// Here we merge two import resolutions.
|
||||
@ -843,10 +837,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
|
||||
// Simple: just copy the old import resolution.
|
||||
let mut new_import_resolution = ImportResolution::new(id, is_public);
|
||||
new_import_resolution.value_target =
|
||||
target_import_resolution.value_target.clone();
|
||||
new_import_resolution.type_target =
|
||||
target_import_resolution.type_target.clone();
|
||||
new_import_resolution.value_target = target_import_resolution.value_target.clone();
|
||||
new_import_resolution.type_target = target_import_resolution.type_target.clone();
|
||||
|
||||
import_resolutions.insert(*name, new_import_resolution);
|
||||
}
|
||||
@ -865,8 +857,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
|
||||
// Add external module children from the containing module.
|
||||
for (&name, module) in target_module.external_module_children.borrow().iter() {
|
||||
let name_bindings =
|
||||
Rc::new(Resolver::create_name_bindings_from_module(module.clone()));
|
||||
let name_bindings = Rc::new(Resolver::create_name_bindings_from_module(module.clone()));
|
||||
self.merge_import_resolution(module_,
|
||||
target_module.clone(),
|
||||
import_directive,
|
||||
@ -876,11 +867,12 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
|
||||
// Record the destination of this import
|
||||
if let Some(did) = target_module.def_id.get() {
|
||||
self.resolver.def_map.borrow_mut().insert(id, PathResolution {
|
||||
base_def: DefMod(did),
|
||||
last_private: lp,
|
||||
depth: 0
|
||||
});
|
||||
self.resolver.def_map.borrow_mut().insert(id,
|
||||
PathResolution {
|
||||
base_def: DefMod(did),
|
||||
last_private: lp,
|
||||
depth: 0,
|
||||
});
|
||||
}
|
||||
|
||||
debug!("(resolving glob import) successfully resolved import");
|
||||
@ -898,10 +890,11 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
|
||||
let mut import_resolutions = module_.import_resolutions.borrow_mut();
|
||||
let dest_import_resolution = import_resolutions.entry(name)
|
||||
.or_insert_with(|| ImportResolution::new(id, is_public));
|
||||
.or_insert_with(|| {
|
||||
ImportResolution::new(id, is_public)
|
||||
});
|
||||
|
||||
debug!("(resolving glob import) writing resolution `{}` in `{}` \
|
||||
to `{}`",
|
||||
debug!("(resolving glob import) writing resolution `{}` in `{}` to `{}`",
|
||||
name,
|
||||
module_to_string(&*containing_module),
|
||||
module_to_string(module_));
|
||||
@ -918,18 +911,20 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
};
|
||||
debug!("(resolving glob import) ... for {} target", namespace_name);
|
||||
if dest_import_resolution.shadowable(namespace) == Shadowable::Never {
|
||||
let msg = format!("a {} named `{}` has already been imported \
|
||||
in this module",
|
||||
let msg = format!("a {} named `{}` has already been imported in this \
|
||||
module",
|
||||
namespace_name,
|
||||
name);
|
||||
span_err!(self.resolver.session, import_directive.span, E0251, "{}", msg);
|
||||
span_err!(self.resolver.session,
|
||||
import_directive.span,
|
||||
E0251,
|
||||
"{}",
|
||||
msg);
|
||||
} else {
|
||||
let target = Target::new(containing_module.clone(),
|
||||
name_bindings.clone(),
|
||||
import_directive.shadowable);
|
||||
dest_import_resolution.set_target_and_id(namespace,
|
||||
Some(target),
|
||||
id);
|
||||
dest_import_resolution.set_target_and_id(namespace, Some(target), id);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -939,11 +934,10 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
|
||||
dest_import_resolution.is_public = is_public;
|
||||
|
||||
self.check_for_conflicts_between_imports_and_items(
|
||||
module_,
|
||||
dest_import_resolution,
|
||||
import_directive.span,
|
||||
name);
|
||||
self.check_for_conflicts_between_imports_and_items(module_,
|
||||
dest_import_resolution,
|
||||
import_directive.span,
|
||||
name);
|
||||
}
|
||||
|
||||
/// Checks that imported names and items don't have the same name.
|
||||
@ -963,28 +957,31 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
TypeNS => {
|
||||
if let Some(ref ty_def) = *target.bindings.type_def.borrow() {
|
||||
match ty_def.module_def {
|
||||
Some(ref module)
|
||||
if module.kind.get() == ModuleKind::NormalModuleKind =>
|
||||
"module",
|
||||
Some(ref module)
|
||||
if module.kind.get() == ModuleKind::TraitModuleKind =>
|
||||
"trait",
|
||||
Some(ref module) if module.kind.get() ==
|
||||
ModuleKind::NormalModuleKind => "module",
|
||||
Some(ref module) if module.kind.get() ==
|
||||
ModuleKind::TraitModuleKind => "trait",
|
||||
_ => "type",
|
||||
}
|
||||
} else { "type" }
|
||||
},
|
||||
} else {
|
||||
"type"
|
||||
}
|
||||
}
|
||||
ValueNS => "value",
|
||||
};
|
||||
span_err!(self.resolver.session, import_span, E0252,
|
||||
"a {} named `{}` has already been imported \
|
||||
in this module", ns_word,
|
||||
name);
|
||||
span_err!(self.resolver.session,
|
||||
import_span,
|
||||
E0252,
|
||||
"a {} named `{}` has already been imported in this module",
|
||||
ns_word,
|
||||
name);
|
||||
let use_id = import_resolution.id(namespace);
|
||||
let item = self.resolver.ast_map.expect_item(use_id);
|
||||
// item is syntax::ast::Item;
|
||||
span_note!(self.resolver.session, item.span,
|
||||
"previous import of `{}` here",
|
||||
name);
|
||||
span_note!(self.resolver.session,
|
||||
item.span,
|
||||
"previous import of `{}` here",
|
||||
name);
|
||||
}
|
||||
Some(_) | None => {}
|
||||
}
|
||||
@ -997,8 +994,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
name: Name,
|
||||
namespace: Namespace) {
|
||||
if !name_bindings.defined_in_namespace_with(namespace, DefModifiers::IMPORTABLE) {
|
||||
let msg = format!("`{}` is not directly importable",
|
||||
name);
|
||||
let msg = format!("`{}` is not directly importable", name);
|
||||
span_err!(self.resolver.session, import_span, E0253, "{}", &msg[..]);
|
||||
}
|
||||
}
|
||||
@ -1006,8 +1002,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
/// Checks that imported names and items don't have the same name.
|
||||
fn check_for_conflicts_between_imports_and_items(&mut self,
|
||||
module: &Module,
|
||||
import_resolution:
|
||||
&ImportResolution,
|
||||
import_resolution: &ImportResolution,
|
||||
import_span: Span,
|
||||
name: Name) {
|
||||
// First, check for conflicts between imports and `extern crate`s.
|
||||
@ -1016,8 +1011,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
.contains_key(&name) {
|
||||
match import_resolution.type_target {
|
||||
Some(ref target) if target.shadowable != Shadowable::Always => {
|
||||
let msg = format!("import `{0}` conflicts with imported \
|
||||
crate in this module \
|
||||
let msg = format!("import `{0}` conflicts with imported crate in this module \
|
||||
(maybe you meant `use {0}::*`?)",
|
||||
name);
|
||||
span_err!(self.resolver.session, import_span, E0254, "{}", &msg[..]);
|
||||
@ -1031,7 +1025,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
let name_bindings = match children.get(&name) {
|
||||
None => {
|
||||
// There can't be any conflicts.
|
||||
return
|
||||
return;
|
||||
}
|
||||
Some(ref name_bindings) => (*name_bindings).clone(),
|
||||
};
|
||||
@ -1039,7 +1033,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
match import_resolution.value_target {
|
||||
Some(ref target) if target.shadowable != Shadowable::Always => {
|
||||
if let Some(ref value) = *name_bindings.value_def.borrow() {
|
||||
span_err!(self.resolver.session, import_span, E0255,
|
||||
span_err!(self.resolver.session,
|
||||
import_span,
|
||||
E0255,
|
||||
"import `{}` conflicts with value in this module",
|
||||
name);
|
||||
if let Some(span) = value.value_span {
|
||||
@ -1054,17 +1050,18 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
Some(ref target) if target.shadowable != Shadowable::Always => {
|
||||
if let Some(ref ty) = *name_bindings.type_def.borrow() {
|
||||
let (what, note) = match ty.module_def {
|
||||
Some(ref module)
|
||||
if module.kind.get() == ModuleKind::NormalModuleKind =>
|
||||
("existing submodule", "note conflicting module here"),
|
||||
Some(ref module)
|
||||
if module.kind.get() == ModuleKind::TraitModuleKind =>
|
||||
("trait in this module", "note conflicting trait here"),
|
||||
_ => ("type in this module", "note conflicting type here"),
|
||||
Some(ref module) if module.kind.get() == ModuleKind::NormalModuleKind =>
|
||||
("existing submodule", "note conflicting module here"),
|
||||
Some(ref module) if module.kind.get() == ModuleKind::TraitModuleKind =>
|
||||
("trait in this module", "note conflicting trait here"),
|
||||
_ => ("type in this module", "note conflicting type here"),
|
||||
};
|
||||
span_err!(self.resolver.session, import_span, E0256,
|
||||
span_err!(self.resolver.session,
|
||||
import_span,
|
||||
E0256,
|
||||
"import `{}` conflicts with {}",
|
||||
name, what);
|
||||
name,
|
||||
what);
|
||||
if let Some(span) = ty.type_span {
|
||||
self.resolver.session.span_note(span, note);
|
||||
}
|
||||
@ -1075,28 +1072,25 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn import_path_to_string(names: &[Name],
|
||||
subclass: ImportDirectiveSubclass)
|
||||
-> String {
|
||||
fn import_path_to_string(names: &[Name], subclass: ImportDirectiveSubclass) -> String {
|
||||
if names.is_empty() {
|
||||
import_directive_subclass_to_string(subclass)
|
||||
} else {
|
||||
(format!("{}::{}",
|
||||
names_to_string(names),
|
||||
import_directive_subclass_to_string(subclass))).to_string()
|
||||
import_directive_subclass_to_string(subclass)))
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
fn import_directive_subclass_to_string(subclass: ImportDirectiveSubclass) -> String {
|
||||
match subclass {
|
||||
SingleImport(_, source) => source.to_string(),
|
||||
GlobImport => "*".to_string()
|
||||
GlobImport => "*".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resolve_imports(resolver: &mut Resolver) {
|
||||
let mut import_resolver = ImportResolver {
|
||||
resolver: resolver,
|
||||
};
|
||||
let mut import_resolver = ImportResolver { resolver: resolver };
|
||||
import_resolver.resolve_imports();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user