Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error for some unresolved imports #6443

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2282,25 +2282,27 @@ pub impl Resolver {
}

let i = import_resolution;
let mut resolve_fail = false;
let mut priv_fail = false;
match (i.value_target, i.type_target) {
// If this name wasn't found in either namespace, it's definitely
// unresolved.
(None, None) => { return Failed; }
(None, None) => { resolve_fail = true; }
// If it's private, it's also unresolved.
(Some(t), None) | (None, Some(t)) => {
let bindings = &mut *t.bindings;
match bindings.type_def {
Some(ref type_def) => {
if type_def.privacy == Private {
return Failed;
priv_fail = true;
}
}
_ => ()
}
match bindings.value_def {
Some(ref value_def) => {
if value_def.privacy == Private {
return Failed;
priv_fail = true;
}
}
_ => ()
Expand All @@ -2313,13 +2315,25 @@ pub impl Resolver {
(Some(ref value_def), Some(ref type_def)) =>
if value_def.privacy == Private
&& type_def.privacy == Private {
return Failed;
priv_fail = true;
},
_ => ()
}
}
}

if resolve_fail {
self.session.err(fmt!("unresolved import: there is no `%s` in `%s`",
*self.session.str_of(source),
self.module_to_str(containing_module)));
return Failed;
} else if priv_fail {
self.session.err(fmt!("unresolved import: found `%s` in `%s` but it is private",
*self.session.str_of(source),
self.module_to_str(containing_module)));
return Failed;
}

assert!(import_resolution.outstanding_references >= 1);
import_resolution.outstanding_references -= 1;

Expand Down Expand Up @@ -2491,7 +2505,8 @@ pub impl Resolver {
*segment_name));
return Failed;
}
self.session.span_err(span, ~"unresolved name");
self.session.span_err(span, fmt!("unresolved import: could not find `%s` in \
`%s`.", *segment_name, module_name));
return Failed;
}
Indeterminate => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/import2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use baz::zed::bar; //~ ERROR unresolved name
use baz::zed::bar; //~ ERROR unresolved import
//~^ ERROR failed to resolve import

mod baz {}
Expand Down