Skip to content

Fix up unresolved error handling some more #6485

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 6 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
31 changes: 22 additions & 9 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,8 @@ pub impl Resolver {
self.resolve_single_import(module_,
containing_module,
target,
source);
source,
import_directive.span);
}
GlobImport => {
let span = import_directive.span;
Expand Down Expand Up @@ -2121,7 +2122,8 @@ pub impl Resolver {
module_: @mut Module,
containing_module: @mut Module,
target: ident,
source: ident)
source: ident,
span: span)
-> ResolveResult<()> {
debug!("(resolving single import) resolving `%s` = `%s::%s` from \
`%s`",
Expand Down Expand Up @@ -2325,14 +2327,14 @@ pub impl Resolver {
}

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)));
self.session.span_err(span, 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)));
self.session.span_err(span, fmt!("unresolved import: found `%s` in `%s` but it is \
private", *self.session.str_of(source),
self.module_to_str(containing_module)));
return Failed;
}

Expand Down Expand Up @@ -2593,7 +2595,18 @@ 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);
match str::rfind(self.idents_to_str(module_path), |c| { c == ':' }) {
Some(idx) => {
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
// colon
str::substr(mpath, 0, idx - 1)));
},
None => (),
};
return Failed;
}
Indeterminate => {
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/issue-2123.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

use x = m::f; //~ ERROR failed to resolve import
//~^ unresolved import: there is no `f` in `m`

mod m {
}
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/issue-2937.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

use x = m::f; //~ ERROR failed to resolve import
//~^ ERROR unresolved import: there is no `f` in `m`

mod m {
}
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/issue-3993-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

use zoo::{duck, goose}; //~ ERROR failed to resolve import
//~^ ERROR unresolved import: found `goose` in `zoo` but it is private

mod zoo {
pub enum bird {
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/issue-3993-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

use zoo::fly; //~ ERROR failed to resolve import
//~^ ERROR unresolved import: found `fly` in `zoo` but it is private

mod zoo {
priv type fly = ();
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/issue-3993.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

use zoo::fly; //~ ERROR failed to resolve import
//~^ ERROR unresolved import: found `fly` in `zoo` but it is private

mod zoo {
priv fn fly() {}
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/super-at-top-level.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::f; //~ ERROR unresolved name
//~^ ERROR failed to resolve import
use super::f; //~ ERROR failed to resolve import

fn main() {
}
10 changes: 8 additions & 2 deletions 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
//~^ ERROR failed to resolve import
use foo::bar; //~ ERROR unresolved import. maybe a missing `extern mod foo`?
//~^ ERROR failed to resolve import `foo::bar`
use x = bar::baz; //~ ERROR unresolved import: there is no `baz` in `bar`
//~^ ERROR failed to resolve import `bar::baz`

mod bar {
struct bar;
}