Skip to content

Better error reporting with renaming imports #6465

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

Closed
wants to merge 4 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
7 changes: 6 additions & 1 deletion src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2593,7 +2593,12 @@ pub impl Resolver {
let start_index;
match module_prefix_result {
Failed => {
self.session.span_err(span, ~"unresolved name");
let mpath = self.idents_to_str(module_path);
let idx = str::rfind(self.idents_to_str(module_path), |c| { c == ':' }).unwrap();
self.session.span_err(span, fmt!("unresolved import: could not find `%s` in `%s`",
str::substr(mpath, idx, mpath.len() - idx),
// idx - 1 to account for the extra semicolon
str::substr(mpath, 0, idx - 1)));
return Failed;
}
Indeterminate => {
Expand Down
8 changes: 7 additions & 1 deletion src/test/compile-fail/unresolved-import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use foo::bar; //~ ERROR unresolved import. maybe a missing
use foo::bar; //~ ERROR unresolved import. maybe a missing `extern mod foo`?
//~^ ERROR failed to resolve import
use x = bar::baz; //~ ERROR unresolved import: could not find `baz` in `bar`
//~^ ERROR failed to resolve import

mod bar {
struct bar;
}