Improve the error message for paths with too many initial supers

This commit is contained in:
Jeffrey Seyfried 2016-03-13 06:00:54 +00:00
parent 8988c4538e
commit 4b6b506ef4
2 changed files with 7 additions and 21 deletions

View File

@ -1382,28 +1382,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
module_to_string(self.current_module));
// Resolve the module prefix, if any.
let module_prefix_result = self.resolve_module_prefix(module_path);
let module_prefix_result = self.resolve_module_prefix(module_path, span);
let search_module;
let start_index;
match module_prefix_result {
Failed(None) => {
let mpath = names_to_string(module_path);
let mpath = &mpath[..];
match mpath.rfind(':') {
Some(idx) => {
let msg = format!("Could not find `{}` in `{}`",
// idx +- 1 to account for the
// colons on either side
&mpath[idx + 1..],
&mpath[..idx - 1]);
return Failed(Some((span, msg)));
}
None => {
return Failed(None);
}
}
}
Failed(err) => return Failed(err),
Indeterminate => {
debug!("(resolving module path for import) indeterminate; bailing");
@ -1531,7 +1514,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
/// Resolves a "module prefix". A module prefix is one or both of (a) `self::`;
/// (b) some chain of `super::`.
/// grammar: (SELF MOD_SEP ) ? (SUPER MOD_SEP) *
fn resolve_module_prefix(&mut self, module_path: &[Name])
fn resolve_module_prefix(&mut self, module_path: &[Name], span: Span)
-> ResolveResult<ModulePrefixResult<'a>> {
// Start at the current module if we see `self` or `super`, or at the
// top of the crate otherwise.
@ -1548,7 +1531,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
debug!("(resolving module prefix) resolving `super` at {}",
module_to_string(&containing_module));
match self.get_nearest_normal_module_parent(containing_module) {
None => return Failed(None),
None => {
let msg = "There are too many initial `super`s.".into();
return Failed(Some((span, msg)));
}
Some(new_module) => {
containing_module = new_module;
i += 1;

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use super::f; //~ ERROR unresolved import `super::f`
use super::f; //~ ERROR unresolved import `super::f`. There are too many initial `super`s.
fn main() {
}