auto merge of #14879 : Ryman/rust/resolve_super_hint_cut, r=alexcrichton
This commit is contained in:
commit
557b9e7f0f
@ -206,10 +206,12 @@ impl ReducedGraphParent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ErrorMessage = Option<(Span, String)>;
|
||||||
|
|
||||||
enum ResolveResult<T> {
|
enum ResolveResult<T> {
|
||||||
Failed, // Failed to resolve the name.
|
Failed(ErrorMessage), // Failed to resolve the name, optional helpful error message.
|
||||||
Indeterminate, // Couldn't determine due to unresolved globs.
|
Indeterminate, // Couldn't determine due to unresolved globs.
|
||||||
Success(T) // Successfully resolved the import.
|
Success(T) // Successfully resolved the import.
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> ResolveResult<T> {
|
impl<T> ResolveResult<T> {
|
||||||
@ -1485,26 +1487,22 @@ impl<'a> Resolver<'a> {
|
|||||||
|
|
||||||
ViewItemExternCrate(name, _, node_id) => {
|
ViewItemExternCrate(name, _, node_id) => {
|
||||||
// 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
|
||||||
match self.session.cstore.find_extern_mod_stmt_cnum(node_id) {
|
for &crate_id in self.session.cstore
|
||||||
Some(crate_id) => {
|
.find_extern_mod_stmt_cnum(node_id).iter() {
|
||||||
let def_id = DefId { krate: crate_id, node: 0 };
|
let def_id = DefId { krate: crate_id, node: 0 };
|
||||||
self.external_exports.insert(def_id);
|
self.external_exports.insert(def_id);
|
||||||
let parent_link = ModuleParentLink
|
let parent_link =
|
||||||
(parent.module().downgrade(), name);
|
ModuleParentLink(parent.module().downgrade(), name);
|
||||||
let external_module = Rc::new(Module::new(parent_link,
|
let external_module = Rc::new(Module::new(parent_link,
|
||||||
Some(def_id),
|
Some(def_id),
|
||||||
NormalModuleKind,
|
NormalModuleKind,
|
||||||
false,
|
false,
|
||||||
true));
|
true));
|
||||||
|
debug!("(build reduced graph for item) found extern `{}`",
|
||||||
parent.module().external_module_children
|
self.module_to_str(&*external_module));
|
||||||
.borrow_mut().insert(name.name,
|
parent.module().external_module_children.borrow_mut()
|
||||||
external_module.clone());
|
.insert(name.name, external_module.clone());
|
||||||
|
self.build_reduced_graph_for_external_crate(external_module);
|
||||||
self.build_reduced_graph_for_external_crate(
|
|
||||||
external_module);
|
|
||||||
}
|
|
||||||
None => {} // Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1997,7 +1995,9 @@ impl<'a> Resolver<'a> {
|
|||||||
fn resolve_imports_for_module_subtree(&mut self, module_: Rc<Module>) {
|
fn resolve_imports_for_module_subtree(&mut self, module_: Rc<Module>) {
|
||||||
debug!("(resolving imports for module subtree) resolving {}",
|
debug!("(resolving imports for module subtree) resolving {}",
|
||||||
self.module_to_str(&*module_));
|
self.module_to_str(&*module_));
|
||||||
|
let orig_module = replace(&mut self.current_module, module_.clone());
|
||||||
self.resolve_imports_for_module(module_.clone());
|
self.resolve_imports_for_module(module_.clone());
|
||||||
|
self.current_module = orig_module;
|
||||||
|
|
||||||
self.populate_module_if_necessary(&module_);
|
self.populate_module_if_necessary(&module_);
|
||||||
for (_, child_node) in module_.children.borrow().iter() {
|
for (_, child_node) in module_.children.borrow().iter() {
|
||||||
@ -2032,22 +2032,21 @@ impl<'a> Resolver<'a> {
|
|||||||
let import_directive = imports.get(import_index);
|
let import_directive = imports.get(import_index);
|
||||||
match self.resolve_import_for_module(module.clone(),
|
match self.resolve_import_for_module(module.clone(),
|
||||||
import_directive) {
|
import_directive) {
|
||||||
Failed => {
|
Failed(err) => {
|
||||||
// We presumably emitted an error. Continue.
|
let (span, help) = match err {
|
||||||
let msg = format!("failed to resolve import `{}`",
|
Some((span, msg)) => (span, format!(". {}", msg)),
|
||||||
self.import_path_to_str(
|
None => (import_directive.span, String::new())
|
||||||
import_directive.module_path
|
};
|
||||||
.as_slice(),
|
let msg = format!("unresolved import `{}`{}",
|
||||||
import_directive.subclass));
|
self.import_path_to_str(
|
||||||
self.resolve_error(import_directive.span, msg.as_slice());
|
import_directive.module_path
|
||||||
}
|
.as_slice(),
|
||||||
Indeterminate => {
|
import_directive.subclass),
|
||||||
// Bail out. We'll come around next time.
|
help);
|
||||||
break;
|
self.resolve_error(span, msg.as_slice());
|
||||||
}
|
|
||||||
Success(()) => {
|
|
||||||
// Good. Continue.
|
|
||||||
}
|
}
|
||||||
|
Indeterminate => break, // Bail out. We'll come around next time.
|
||||||
|
Success(()) => () // Good. Continue.
|
||||||
}
|
}
|
||||||
|
|
||||||
module.resolved_import_count
|
module.resolved_import_count
|
||||||
@ -2111,7 +2110,7 @@ impl<'a> Resolver<'a> {
|
|||||||
module_: Rc<Module>,
|
module_: Rc<Module>,
|
||||||
import_directive: &ImportDirective)
|
import_directive: &ImportDirective)
|
||||||
-> ResolveResult<()> {
|
-> ResolveResult<()> {
|
||||||
let mut resolution_result = Failed;
|
let mut resolution_result = Failed(None);
|
||||||
let module_path = &import_directive.module_path;
|
let module_path = &import_directive.module_path;
|
||||||
|
|
||||||
debug!("(resolving import for module) resolving import `{}::...` in \
|
debug!("(resolving import for module) resolving import `{}::...` in \
|
||||||
@ -2129,8 +2128,10 @@ impl<'a> Resolver<'a> {
|
|||||||
DontUseLexicalScope,
|
DontUseLexicalScope,
|
||||||
import_directive.span,
|
import_directive.span,
|
||||||
ImportSearch) {
|
ImportSearch) {
|
||||||
|
Failed(err) => {
|
||||||
Failed => None,
|
resolution_result = Failed(err);
|
||||||
|
None
|
||||||
|
},
|
||||||
Indeterminate => {
|
Indeterminate => {
|
||||||
resolution_result = Indeterminate;
|
resolution_result = Indeterminate;
|
||||||
None
|
None
|
||||||
@ -2408,12 +2409,10 @@ impl<'a> Resolver<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if value_result.is_unbound() && type_result.is_unbound() {
|
if value_result.is_unbound() && type_result.is_unbound() {
|
||||||
let msg = format!("unresolved import: there is no \
|
let msg = format!("There is no `{}` in `{}`",
|
||||||
`{}` in `{}`",
|
|
||||||
token::get_ident(source),
|
token::get_ident(source),
|
||||||
self.module_to_str(&*containing_module));
|
self.module_to_str(&*containing_module));
|
||||||
self.resolve_error(directive.span, msg.as_slice());
|
return Failed(Some((directive.span, msg)));
|
||||||
return Failed;
|
|
||||||
}
|
}
|
||||||
let value_used_public = value_used_reexport || value_used_public;
|
let value_used_public = value_used_reexport || value_used_public;
|
||||||
let type_used_public = type_used_reexport || type_used_public;
|
let type_used_public = type_used_reexport || type_used_public;
|
||||||
@ -2611,6 +2610,22 @@ impl<'a> Resolver<'a> {
|
|||||||
name_search_type: NameSearchType,
|
name_search_type: NameSearchType,
|
||||||
lp: LastPrivate)
|
lp: LastPrivate)
|
||||||
-> ResolveResult<(Rc<Module>, LastPrivate)> {
|
-> ResolveResult<(Rc<Module>, LastPrivate)> {
|
||||||
|
fn search_parent_externals(needle: Name, module: &Rc<Module>)
|
||||||
|
-> Option<Rc<Module>> {
|
||||||
|
module.external_module_children.borrow()
|
||||||
|
.find_copy(&needle)
|
||||||
|
.map(|_| module.clone())
|
||||||
|
.or_else(|| {
|
||||||
|
match module.parent_link.clone() {
|
||||||
|
ModuleParentLink(parent, _) => {
|
||||||
|
search_parent_externals(needle,
|
||||||
|
&parent.upgrade().unwrap())
|
||||||
|
}
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
let mut search_module = module_;
|
let mut search_module = module_;
|
||||||
let mut index = index;
|
let mut index = index;
|
||||||
let module_path_len = module_path.len();
|
let module_path_len = module_path.len();
|
||||||
@ -2626,29 +2641,41 @@ impl<'a> Resolver<'a> {
|
|||||||
TypeNS,
|
TypeNS,
|
||||||
name_search_type,
|
name_search_type,
|
||||||
false) {
|
false) {
|
||||||
Failed => {
|
Failed(None) => {
|
||||||
let segment_name = token::get_ident(name);
|
let segment_name = token::get_ident(name);
|
||||||
let module_name = self.module_to_str(&*search_module);
|
let module_name = self.module_to_str(&*search_module);
|
||||||
if "???" == module_name.as_slice() {
|
let mut span = span;
|
||||||
let span = Span {
|
let msg = if "???" == module_name.as_slice() {
|
||||||
lo: span.lo,
|
span.hi = span.lo + Pos::from_uint(segment_name.get().len());
|
||||||
hi: span.lo + Pos::from_uint(segment_name.get().len()),
|
|
||||||
expn_info: span.expn_info,
|
match search_parent_externals(name.name,
|
||||||
};
|
&self.current_module) {
|
||||||
self.resolve_error(span,
|
Some(module) => {
|
||||||
format!("unresolved import. maybe \
|
let path_str = self.idents_to_str(module_path);
|
||||||
a missing `extern crate \
|
let target_mod_str = self.module_to_str(&*module);
|
||||||
{}`?",
|
let current_mod_str =
|
||||||
segment_name).as_slice());
|
self.module_to_str(&*self.current_module);
|
||||||
return Failed;
|
|
||||||
}
|
let prefix = if target_mod_str == current_mod_str {
|
||||||
self.resolve_error(span,
|
"self::".to_string()
|
||||||
format!("unresolved import: could not \
|
} else {
|
||||||
find `{}` in `{}`.",
|
format!("{}::", target_mod_str)
|
||||||
segment_name,
|
};
|
||||||
module_name).as_slice());
|
|
||||||
return Failed;
|
format!("Did you mean `{}{}`?", prefix, path_str)
|
||||||
|
},
|
||||||
|
None => format!("Maybe a missing `extern crate {}`?",
|
||||||
|
segment_name),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
format!("Could not find `{}` in `{}`.",
|
||||||
|
segment_name,
|
||||||
|
module_name)
|
||||||
|
};
|
||||||
|
|
||||||
|
return Failed(Some((span, msg)));
|
||||||
}
|
}
|
||||||
|
Failed(err) => return Failed(err),
|
||||||
Indeterminate => {
|
Indeterminate => {
|
||||||
debug!("(resolving module path for import) module \
|
debug!("(resolving module path for import) module \
|
||||||
resolution is indeterminate: {}",
|
resolution is indeterminate: {}",
|
||||||
@ -2662,13 +2689,10 @@ impl<'a> Resolver<'a> {
|
|||||||
Some(ref type_def) => {
|
Some(ref type_def) => {
|
||||||
match type_def.module_def {
|
match type_def.module_def {
|
||||||
None => {
|
None => {
|
||||||
// Not a module.
|
let msg = format!("Not a module `{}`",
|
||||||
self.resolve_error(
|
token::get_ident(name));
|
||||||
span,
|
|
||||||
format!("not a module `{}`",
|
return Failed(Some((span, msg)));
|
||||||
token::get_ident(name))
|
|
||||||
.as_slice());
|
|
||||||
return Failed;
|
|
||||||
}
|
}
|
||||||
Some(ref module_def) => {
|
Some(ref module_def) => {
|
||||||
// If we're doing the search for an
|
// If we're doing the search for an
|
||||||
@ -2678,11 +2702,10 @@ impl<'a> Resolver<'a> {
|
|||||||
module_def.kind.get()) {
|
module_def.kind.get()) {
|
||||||
(ImportSearch, TraitModuleKind) |
|
(ImportSearch, TraitModuleKind) |
|
||||||
(ImportSearch, ImplModuleKind) => {
|
(ImportSearch, ImplModuleKind) => {
|
||||||
self.resolve_error(
|
let msg =
|
||||||
span,
|
"Cannot import from a trait or \
|
||||||
"cannot import from a trait \
|
type implementation".to_string();
|
||||||
or type implementation");
|
return Failed(Some((span, msg)));
|
||||||
return Failed;
|
|
||||||
}
|
}
|
||||||
(_, _) => {
|
(_, _) => {
|
||||||
search_module = module_def.clone();
|
search_module = module_def.clone();
|
||||||
@ -2708,11 +2731,9 @@ impl<'a> Resolver<'a> {
|
|||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// There are no type bindings at all.
|
// There are no type bindings at all.
|
||||||
self.resolve_error(
|
let msg = format!("Not a module `{}`",
|
||||||
span,
|
token::get_ident(name));
|
||||||
format!("not a module `{}`",
|
return Failed(Some((span, msg)));
|
||||||
token::get_ident(name)).as_slice());
|
|
||||||
return Failed;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2752,24 +2773,22 @@ impl<'a> Resolver<'a> {
|
|||||||
let start_index;
|
let start_index;
|
||||||
let last_private;
|
let last_private;
|
||||||
match module_prefix_result {
|
match module_prefix_result {
|
||||||
Failed => {
|
Failed(None) => {
|
||||||
let mpath = self.idents_to_str(module_path);
|
let mpath = self.idents_to_str(module_path);
|
||||||
match mpath.as_slice().rfind(':') {
|
let mpath = mpath.as_slice();
|
||||||
|
match mpath.rfind(':') {
|
||||||
Some(idx) => {
|
Some(idx) => {
|
||||||
self.resolve_error(
|
let msg = format!("Could not find `{}` in `{}`",
|
||||||
span,
|
// idx +- 1 to account for the
|
||||||
format!("unresolved import: could not find `{}` \
|
// colons on either side
|
||||||
in `{}`",
|
mpath.slice_from(idx + 1),
|
||||||
// idx +- 1 to account for the colons on \
|
mpath.slice_to(idx - 1));
|
||||||
// either side
|
return Failed(Some((span, msg)));
|
||||||
mpath.as_slice().slice_from(idx + 1),
|
|
||||||
mpath.as_slice()
|
|
||||||
.slice_to(idx - 1)).as_slice());
|
|
||||||
},
|
},
|
||||||
None => (),
|
None => return Failed(None),
|
||||||
};
|
}
|
||||||
return Failed;
|
|
||||||
}
|
}
|
||||||
|
Failed(err) => return Failed(err),
|
||||||
Indeterminate => {
|
Indeterminate => {
|
||||||
debug!("(resolving module path for import) indeterminate; \
|
debug!("(resolving module path for import) indeterminate; \
|
||||||
bailing");
|
bailing");
|
||||||
@ -2791,14 +2810,10 @@ impl<'a> Resolver<'a> {
|
|||||||
// This is not a crate-relative path. We resolve the
|
// This is not a crate-relative path. We resolve the
|
||||||
// first component of the path in the current lexical
|
// first component of the path in the current lexical
|
||||||
// scope and then proceed to resolve below that.
|
// scope and then proceed to resolve below that.
|
||||||
let result = self.resolve_module_in_lexical_scope(
|
match self.resolve_module_in_lexical_scope(
|
||||||
module_,
|
module_,
|
||||||
module_path[0]);
|
module_path[0]) {
|
||||||
match result {
|
Failed(err) => return Failed(err),
|
||||||
Failed => {
|
|
||||||
self.resolve_error(span, "unresolved name");
|
|
||||||
return Failed;
|
|
||||||
}
|
|
||||||
Indeterminate => {
|
Indeterminate => {
|
||||||
debug!("(resolving module path for import) \
|
debug!("(resolving module path for import) \
|
||||||
indeterminate; bailing");
|
indeterminate; bailing");
|
||||||
@ -2905,7 +2920,7 @@ impl<'a> Resolver<'a> {
|
|||||||
// No more parents. This module was unresolved.
|
// No more parents. This module was unresolved.
|
||||||
debug!("(resolving item in lexical scope) unresolved \
|
debug!("(resolving item in lexical scope) unresolved \
|
||||||
module");
|
module");
|
||||||
return Failed;
|
return Failed(None);
|
||||||
}
|
}
|
||||||
ModuleParentLink(parent_module_node, _) => {
|
ModuleParentLink(parent_module_node, _) => {
|
||||||
match search_module.kind.get() {
|
match search_module.kind.get() {
|
||||||
@ -2915,7 +2930,7 @@ impl<'a> Resolver<'a> {
|
|||||||
scope) unresolved module: not \
|
scope) unresolved module: not \
|
||||||
searching through module \
|
searching through module \
|
||||||
parents");
|
parents");
|
||||||
return Failed;
|
return Failed(None);
|
||||||
}
|
}
|
||||||
ExternModuleKind |
|
ExternModuleKind |
|
||||||
TraitModuleKind |
|
TraitModuleKind |
|
||||||
@ -2936,9 +2951,10 @@ impl<'a> Resolver<'a> {
|
|||||||
namespace,
|
namespace,
|
||||||
PathSearch,
|
PathSearch,
|
||||||
true) {
|
true) {
|
||||||
Failed => {
|
Failed(Some((span, msg))) =>
|
||||||
// Continue up the search chain.
|
self.resolve_error(span, format!("failed to resolve. {}",
|
||||||
}
|
msg)),
|
||||||
|
Failed(None) => (), // Continue up the search chain.
|
||||||
Indeterminate => {
|
Indeterminate => {
|
||||||
// We couldn't see through the higher scope because of an
|
// We couldn't see through the higher scope because of an
|
||||||
// unresolved import higher up. Bail.
|
// unresolved import higher up. Bail.
|
||||||
@ -2976,7 +2992,7 @@ impl<'a> Resolver<'a> {
|
|||||||
debug!("!!! (resolving module in lexical \
|
debug!("!!! (resolving module in lexical \
|
||||||
scope) module wasn't actually a \
|
scope) module wasn't actually a \
|
||||||
module!");
|
module!");
|
||||||
return Failed;
|
return Failed(None);
|
||||||
}
|
}
|
||||||
Some(ref module_def) => {
|
Some(ref module_def) => {
|
||||||
return Success(module_def.clone());
|
return Success(module_def.clone());
|
||||||
@ -2986,7 +3002,7 @@ impl<'a> Resolver<'a> {
|
|||||||
None => {
|
None => {
|
||||||
debug!("!!! (resolving module in lexical scope) module
|
debug!("!!! (resolving module in lexical scope) module
|
||||||
wasn't actually a module!");
|
wasn't actually a module!");
|
||||||
return Failed;
|
return Failed(None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2995,10 +3011,9 @@ impl<'a> Resolver<'a> {
|
|||||||
bailing");
|
bailing");
|
||||||
return Indeterminate;
|
return Indeterminate;
|
||||||
}
|
}
|
||||||
Failed => {
|
Failed(err) => {
|
||||||
debug!("(resolving module in lexical scope) failed to \
|
debug!("(resolving module in lexical scope) failed to resolve");
|
||||||
resolve");
|
return Failed(err);
|
||||||
return Failed;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3076,7 +3091,7 @@ impl<'a> Resolver<'a> {
|
|||||||
debug!("(resolving module prefix) resolving `super` at {}",
|
debug!("(resolving module prefix) resolving `super` at {}",
|
||||||
self.module_to_str(&*containing_module));
|
self.module_to_str(&*containing_module));
|
||||||
match self.get_nearest_normal_module_parent(containing_module) {
|
match self.get_nearest_normal_module_parent(containing_module) {
|
||||||
None => return Failed,
|
None => return Failed(None),
|
||||||
Some(new_module) => {
|
Some(new_module) => {
|
||||||
containing_module = new_module;
|
containing_module = new_module;
|
||||||
i += 1;
|
i += 1;
|
||||||
@ -3173,7 +3188,7 @@ impl<'a> Resolver<'a> {
|
|||||||
// We're out of luck.
|
// We're out of luck.
|
||||||
debug!("(resolving name in module) failed to resolve `{}`",
|
debug!("(resolving name in module) failed to resolve `{}`",
|
||||||
token::get_name(name).get());
|
token::get_name(name).get());
|
||||||
return Failed;
|
return Failed(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn report_unresolved_imports(&mut self, module_: Rc<Module>) {
|
fn report_unresolved_imports(&mut self, module_: Rc<Module>) {
|
||||||
@ -4531,8 +4546,15 @@ impl<'a> Resolver<'a> {
|
|||||||
Indeterminate => {
|
Indeterminate => {
|
||||||
fail!("unexpected indeterminate result");
|
fail!("unexpected indeterminate result");
|
||||||
}
|
}
|
||||||
|
Failed(err) => {
|
||||||
|
match err {
|
||||||
|
Some((span, msg)) => {
|
||||||
|
self.resolve_error(span, format!("failed to resolve: {}",
|
||||||
|
msg));
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
|
||||||
Failed => {
|
|
||||||
debug!("(resolve bare identifier pattern) failed to find {}",
|
debug!("(resolve bare identifier pattern) failed to find {}",
|
||||||
token::get_ident(name));
|
token::get_ident(name));
|
||||||
return BareIdentifierPatternUnresolved;
|
return BareIdentifierPatternUnresolved;
|
||||||
@ -4697,17 +4719,22 @@ impl<'a> Resolver<'a> {
|
|||||||
UseLexicalScope,
|
UseLexicalScope,
|
||||||
path.span,
|
path.span,
|
||||||
PathSearch) {
|
PathSearch) {
|
||||||
Failed => {
|
Failed(err) => {
|
||||||
let msg = format!("use of undeclared module `{}`",
|
let (span, msg) = match err {
|
||||||
self.idents_to_str(module_path_idents.as_slice()));
|
Some((span, msg)) => (span, msg),
|
||||||
self.resolve_error(path.span, msg.as_slice());
|
None => {
|
||||||
|
let msg = format!("Use of undeclared module `{}`",
|
||||||
|
self.idents_to_str(
|
||||||
|
module_path_idents.as_slice()));
|
||||||
|
(path.span, msg)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
self.resolve_error(span, format!("failed to resolve. {}",
|
||||||
|
msg.as_slice()));
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
Indeterminate => fail!("indeterminate unexpected"),
|
||||||
Indeterminate => {
|
|
||||||
fail!("indeterminate unexpected");
|
|
||||||
}
|
|
||||||
|
|
||||||
Success((resulting_module, resulting_last_private)) => {
|
Success((resulting_module, resulting_last_private)) => {
|
||||||
containing_module = resulting_module;
|
containing_module = resulting_module;
|
||||||
last_private = resulting_last_private;
|
last_private = resulting_last_private;
|
||||||
@ -4768,10 +4795,19 @@ impl<'a> Resolver<'a> {
|
|||||||
path.span,
|
path.span,
|
||||||
PathSearch,
|
PathSearch,
|
||||||
LastMod(AllPublic)) {
|
LastMod(AllPublic)) {
|
||||||
Failed => {
|
Failed(err) => {
|
||||||
let msg = format!("use of undeclared module `::{}`",
|
let (span, msg) = match err {
|
||||||
self.idents_to_str(module_path_idents.as_slice()));
|
Some((span, msg)) => (span, msg),
|
||||||
self.resolve_error(path.span, msg.as_slice());
|
None => {
|
||||||
|
let msg = format!("Use of undeclared module `::{}`",
|
||||||
|
self.idents_to_str(
|
||||||
|
module_path_idents.as_slice()));
|
||||||
|
(path.span, msg)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
self.resolve_error(span, format!("failed to resolve. {}",
|
||||||
|
msg.as_slice()));
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4864,7 +4900,13 @@ impl<'a> Resolver<'a> {
|
|||||||
Indeterminate => {
|
Indeterminate => {
|
||||||
fail!("unexpected indeterminate result");
|
fail!("unexpected indeterminate result");
|
||||||
}
|
}
|
||||||
Failed => {
|
Failed(err) => {
|
||||||
|
match err {
|
||||||
|
Some((span, msg)) =>
|
||||||
|
self.resolve_error(span, format!("failed to resolve. {}", msg)),
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
|
||||||
debug!("(resolving item path by identifier in lexical scope) \
|
debug!("(resolving item path by identifier in lexical scope) \
|
||||||
failed to resolve {}", token::get_ident(ident));
|
failed to resolve {}", token::get_ident(ident));
|
||||||
return None;
|
return None;
|
||||||
@ -4879,9 +4921,9 @@ impl<'a> Resolver<'a> {
|
|||||||
rs
|
rs
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_error(&self, span: Span, s: &str) {
|
fn resolve_error<T: Str>(&self, span: Span, s: T) {
|
||||||
if self.emit_errors {
|
if self.emit_errors {
|
||||||
self.session.span_err(span, s);
|
self.session.span_err(span, s.as_slice());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5480,7 +5522,7 @@ impl<'a> Resolver<'a> {
|
|||||||
//
|
//
|
||||||
|
|
||||||
/// A somewhat inefficient routine to obtain the name of a module.
|
/// A somewhat inefficient routine to obtain the name of a module.
|
||||||
fn module_to_str(&mut self, module: &Module) -> String {
|
fn module_to_str(&self, module: &Module) -> String {
|
||||||
let mut idents = Vec::new();
|
let mut idents = Vec::new();
|
||||||
|
|
||||||
fn collect_mod(idents: &mut Vec<ast::Ident>, module: &Module) {
|
fn collect_mod(idents: &mut Vec<ast::Ident>, module: &Module) {
|
||||||
|
@ -19,7 +19,6 @@ extern crate macro_crate_test;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
macro_crate_test::foo();
|
macro_crate_test::foo();
|
||||||
//~^ ERROR unresolved name
|
//~^ ERROR failed to resolve. Use of undeclared module `macro_crate_test`
|
||||||
//~^^ ERROR use of undeclared module `macro_crate_test`
|
//~^^ ERROR unresolved name `macro_crate_test::foo`.
|
||||||
//~^^^ ERROR unresolved name `macro_crate_test::foo`.
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
||||||
// file at the top-level directory of this distribution and at
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
//
|
//
|
||||||
@ -8,8 +8,8 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// error-pattern:failed to resolve import
|
|
||||||
use spam::{ham, eggs};
|
use spam::{ham, eggs};
|
||||||
|
//~^ ERROR unresolved import `spam::eggs`. There is no `eggs` in `spam`
|
||||||
|
|
||||||
mod spam {
|
mod spam {
|
||||||
pub fn ham() { }
|
pub fn ham() { }
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
||||||
// file at the top-level directory of this distribution and at
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
//
|
//
|
||||||
@ -8,9 +8,9 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// error-pattern:failed to resolve import
|
|
||||||
use zed::bar;
|
use zed::bar;
|
||||||
use zed::baz;
|
use zed::baz;
|
||||||
|
//~^ ERROR unresolved import `zed::baz`. There is no `baz` in `zed`
|
||||||
|
|
||||||
|
|
||||||
mod zed {
|
mod zed {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
||||||
// file at the top-level directory of this distribution and at
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
//
|
//
|
||||||
@ -8,8 +8,8 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use baz::zed::bar; //~ ERROR unresolved import
|
use baz::zed::bar;
|
||||||
//~^ ERROR failed to resolve import
|
//~^ ERROR unresolved import `baz::zed::bar`. Could not find `zed` in `baz`.
|
||||||
|
|
||||||
|
|
||||||
mod baz {}
|
mod baz {}
|
||||||
|
@ -16,8 +16,7 @@ use foo::bar;
|
|||||||
|
|
||||||
mod test {
|
mod test {
|
||||||
use bar::foo;
|
use bar::foo;
|
||||||
//~^ ERROR: unresolved import
|
//~^ ERROR unresolved import `bar::foo`. Maybe a missing `extern crate bar`?
|
||||||
//~^^ ERROR: failed to resolve import
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
|
|
||||||
use a::f;
|
use a::f;
|
||||||
use b::f;
|
use b::f;
|
||||||
//~^ ERROR: unresolved import
|
//~^ ERROR: unresolved import `b::f`. There is no `f` in `b`
|
||||||
//~^^ ERROR: failed to resolve import
|
|
||||||
|
|
||||||
mod a { pub fn f() {} }
|
mod a { pub fn f() {} }
|
||||||
mod b { }
|
mod b { }
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
||||||
// file at the top-level directory of this distribution and at
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
//
|
//
|
||||||
@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
#![feature(globs)]
|
#![feature(globs)]
|
||||||
|
|
||||||
use unresolved::*; //~ ERROR unresolved import. maybe a missing
|
use unresolved::*; //~ ERROR unresolved import `unresolved::*`. Maybe a missing `extern crate unres
|
||||||
//~^ ERROR failed to resolve import
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {}
|
||||||
}
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
||||||
// file at the top-level directory of this distribution and at
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
//
|
//
|
||||||
@ -8,11 +8,8 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use x = m::f; //~ ERROR failed to resolve import
|
use x = m::f; //~ ERROR unresolved import `m::f`. There is no `f` in `m`
|
||||||
//~^ unresolved import: there is no `f` in `m`
|
|
||||||
|
|
||||||
mod m {
|
mod m {}
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {}
|
||||||
}
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
||||||
// file at the top-level directory of this distribution and at
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
//
|
//
|
||||||
@ -8,11 +8,8 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use x = m::f; //~ ERROR failed to resolve import
|
use x = m::f; //~ ERROR unresolved import `m::f`. There is no `f` in `m`
|
||||||
//~^ ERROR unresolved import: there is no `f` in `m`
|
|
||||||
|
|
||||||
mod m {
|
mod m {}
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {}
|
||||||
}
|
|
||||||
|
@ -25,9 +25,8 @@ test!(b,
|
|||||||
#[qux]
|
#[qux]
|
||||||
fn main() {
|
fn main() {
|
||||||
a::bar();
|
a::bar();
|
||||||
//~^ ERROR use of undeclared module `a`
|
//~^ ERROR failed to resolve. Use of undeclared module `a`
|
||||||
//~^^ ERROR unresolved name
|
//~^^ ERROR unresolved name `a::bar`
|
||||||
//~^^^ ERROR unresolved name `a::bar`
|
|
||||||
b::bar();
|
b::bar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
|
||||||
// file at the top-level directory of this distribution and at
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
//
|
//
|
||||||
@ -24,14 +24,13 @@ mod bar {
|
|||||||
pub fn foo() {}
|
pub fn foo() {}
|
||||||
|
|
||||||
fn test1() {
|
fn test1() {
|
||||||
use bar::foo; //~ ERROR: unresolved import
|
use bar::foo;
|
||||||
//~^ ERROR: failed to resolve
|
//~^ ERROR unresolved import `bar::foo`. There is no `foo` in `bar`
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test2() {
|
fn test2() {
|
||||||
use bar::glob::foo;
|
use bar::glob::foo;
|
||||||
//~^ ERROR: there is no
|
//~^ ERROR unresolved import `bar::glob::foo`. There is no `foo` in `bar::glob`
|
||||||
//~^^ ERROR: failed to resolve
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[start] fn main(_: int, _: **u8) -> int { 3 }
|
#[start] fn main(_: int, _: **u8) -> int { 3 }
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
|
||||||
// file at the top-level directory of this distribution and at
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
//
|
//
|
||||||
@ -25,8 +25,8 @@ mod bar {
|
|||||||
pub fn foo() {}
|
pub fn foo() {}
|
||||||
|
|
||||||
fn test1() {
|
fn test1() {
|
||||||
use bar::gpriv; //~ ERROR: unresolved import
|
use bar::gpriv;
|
||||||
//~^ ERROR: failed to resolve
|
//~^ ERROR unresolved import `bar::gpriv`. There is no `gpriv` in `bar`
|
||||||
gpriv();
|
gpriv();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
27
src/test/compile-fail/resolve_self_super_hint.rs
Normal file
27
src/test/compile-fail/resolve_self_super_hint.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
mod a {
|
||||||
|
extern crate collections;
|
||||||
|
use collections::HashMap;
|
||||||
|
//~^ ERROR unresolved import `collections::HashMap`. Did you mean `self::collections`?
|
||||||
|
mod b {
|
||||||
|
use collections::HashMap;
|
||||||
|
//~^ ERROR unresolved import `collections::HashMap`. Did you mean `a::collections`?
|
||||||
|
mod c {
|
||||||
|
use collections::HashMap;
|
||||||
|
//~^ ERROR unresolved import `collections::HashMap`. Did you mean `a::collections`?
|
||||||
|
mod d {
|
||||||
|
use collections::HashMap;
|
||||||
|
//~^ ERROR unresolved import `collections::HashMap`. Did you mean `a::collections`?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,7 +8,7 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use super::f; //~ ERROR failed to resolve import
|
use super::f; //~ ERROR unresolved import `super::f`
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
|
||||||
// file at the top-level directory of this distribution and at
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
//
|
//
|
||||||
@ -8,10 +8,9 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use foo::bar; //~ ERROR unresolved import. maybe a missing `extern crate foo`?
|
use foo::bar; //~ ERROR unresolved import `foo::bar`. Maybe a missing `extern crate foo`?
|
||||||
//~^ ERROR failed to resolve import `foo::bar`
|
|
||||||
use x = bar::baz; //~ ERROR unresolved import: there is no `baz` in `bar`
|
use x = bar::baz; //~ ERROR unresolved import `bar::baz`. There is no `baz` in `bar`
|
||||||
//~^ ERROR failed to resolve import `bar::baz`
|
|
||||||
|
|
||||||
mod bar {
|
mod bar {
|
||||||
struct bar;
|
struct bar;
|
||||||
|
@ -12,10 +12,10 @@
|
|||||||
|
|
||||||
extern crate use_from_trait_xc;
|
extern crate use_from_trait_xc;
|
||||||
|
|
||||||
use use_from_trait_xc::Trait::foo; //~ ERROR cannot import from a trait or type implementation
|
use use_from_trait_xc::Trait::foo;
|
||||||
//~^ ERROR failed to resolve import
|
//~^ ERROR unresolved import `use_from_trait_xc::Trait::foo`. Cannot import from a trait or type imp
|
||||||
use use_from_trait_xc::Foo::new; //~ ERROR cannot import from a trait or type implementation
|
|
||||||
//~^ ERROR failed to resolve import
|
|
||||||
|
|
||||||
fn main() {
|
use use_from_trait_xc::Foo::new;
|
||||||
}
|
//~^ ERROR unresolved import `use_from_trait_xc::Foo::new`. Cannot import from a trait or type imple
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
|
@ -8,10 +8,10 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use Trait::foo; //~ ERROR cannot import from a trait or type implementation
|
use Trait::foo;
|
||||||
//~^ ERROR failed to resolve import
|
//~^ ERROR unresolved import `Trait::foo`. Cannot import from a trait or type implementation
|
||||||
use Foo::new; //~ ERROR cannot import from a trait or type implementation
|
use Foo::new;
|
||||||
//~^ ERROR failed to resolve import
|
//~^ ERROR unresolved import `Foo::new`. Cannot import from a trait or type implementation
|
||||||
|
|
||||||
pub trait Trait {
|
pub trait Trait {
|
||||||
fn foo();
|
fn foo();
|
||||||
|
Loading…
Reference in New Issue
Block a user