Skip to content

Commit b6aafe9

Browse files
garethgareth
authored andcommitted
When an import fails to resolve, make the error message say
which import it actually was. This makes debugging imports like: use aa::{x, y, z} easier (for issue #2914).
1 parent 5245ace commit b6aafe9

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/librustc/middle/resolve.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,8 +2086,11 @@ impl Resolver {
20862086
match self.resolve_import_for_module(module_, import_directive) {
20872087
Failed => {
20882088
// We presumably emitted an error. Continue.
2089-
self.session.span_err(import_directive.span,
2090-
~"failed to resolve import");
2089+
let idents = import_directive.module_path.get();
2090+
let msg = fmt!("failed to resolve import: %s",
2091+
self.import_path_to_str(idents,
2092+
*import_directive.subclass));
2093+
self.session.span_err(import_directive.span, msg);
20912094
}
20922095
Indeterminate => {
20932096
// Bail out. We'll come around next time.
@@ -2117,6 +2120,26 @@ impl Resolver {
21172120
// XXX: Shouldn't copy here. We need string builder functionality.
21182121
return result;
21192122
}
2123+
2124+
fn import_directive_subclass_to_str(subclass: ImportDirectiveSubclass)
2125+
-> ~str {
2126+
match subclass {
2127+
SingleImport(_target, source, _ns) => self.session.str_of(source),
2128+
GlobImport => ~"*"
2129+
}
2130+
}
2131+
2132+
fn import_path_to_str(idents: ~[ident], subclass: ImportDirectiveSubclass)
2133+
-> ~str {
2134+
if idents.is_empty() {
2135+
self.import_directive_subclass_to_str(subclass)
2136+
} else {
2137+
fmt!("%s::%s",
2138+
self.idents_to_str(idents),
2139+
self.import_directive_subclass_to_str(subclass))
2140+
}
2141+
}
2142+
21202143
/**
21212144
* Attempts to resolve the given import. The return value indicates
21222145
* failure if we're certain the name does not exist, indeterminate if we

0 commit comments

Comments
 (0)