Skip to content

Commit 08d9c5b

Browse files
committed
Merge pull request #4312 from Dretch/issue-2914
Work towards fixing issue #2914
2 parents 4dde334 + 624421a commit 08d9c5b

File tree

1 file changed

+35
-48
lines changed

1 file changed

+35
-48
lines changed

src/librustc/middle/resolve.rs

+35-48
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.
@@ -2103,20 +2106,29 @@ impl Resolver {
21032106
}
21042107

21052108
fn idents_to_str(idents: ~[ident]) -> ~str {
2106-
// XXX: str::connect should do this.
2107-
let mut result = ~"";
2108-
let mut first = true;
2109-
for idents.each() |ident| {
2110-
if first {
2111-
first = false;
2112-
} else {
2113-
result += ~"::";
2114-
}
2115-
result += self.session.str_of(*ident);
2116-
}
2117-
// XXX: Shouldn't copy here. We need string builder functionality.
2118-
return result;
2109+
let ident_strs = idents.map(|&ident| self.session.str_of(ident));
2110+
return str::connect(ident_strs, "::");
21192111
}
2112+
2113+
fn import_directive_subclass_to_str(subclass: ImportDirectiveSubclass)
2114+
-> ~str {
2115+
match subclass {
2116+
SingleImport(_target, source, _ns) => self.session.str_of(source),
2117+
GlobImport => ~"*"
2118+
}
2119+
}
2120+
2121+
fn import_path_to_str(idents: ~[ident], subclass: ImportDirectiveSubclass)
2122+
-> ~str {
2123+
if idents.is_empty() {
2124+
self.import_directive_subclass_to_str(subclass)
2125+
} else {
2126+
fmt!("%s::%s",
2127+
self.idents_to_str(idents),
2128+
self.import_directive_subclass_to_str(subclass))
2129+
}
2130+
}
2131+
21202132
/**
21212133
* Attempts to resolve the given import. The return value indicates
21222134
* failure if we're certain the name does not exist, indeterminate if we
@@ -4501,17 +4513,14 @@ impl Resolver {
45014513
// Write the result into the def map.
45024514
debug!("(resolving type) writing resolution for `%s` \
45034515
(id %d)",
4504-
connect(path.idents.map(
4505-
|x| self.session.str_of(*x)), ~"::"),
4516+
self.idents_to_str(path.idents),
45064517
path_id);
45074518
self.record_def(path_id, def);
45084519
}
45094520
None => {
45104521
self.session.span_err
45114522
(ty.span, fmt!("use of undeclared type name `%s`",
4512-
connect(path.idents.map(
4513-
|x| self.session.str_of(*x)),
4514-
~"::")));
4523+
self.idents_to_str(path.idents)));
45154524
}
45164525
}
45174526
}
@@ -4705,9 +4714,7 @@ impl Resolver {
47054714
self.session.span_err(
47064715
path.span,
47074716
fmt!("`%s` does not name a structure",
4708-
connect(path.idents.map(
4709-
|x| self.session.str_of(*x)),
4710-
~"::")));
4717+
self.idents_to_str(path.idents)));
47114718
}
47124719
}
47134720
}
@@ -5103,14 +5110,11 @@ impl Resolver {
51035110
Some(def) => {
51045111
// Write the result into the def map.
51055112
debug!("(resolving expr) resolved `%s`",
5106-
connect(path.idents.map(
5107-
|x| self.session.str_of(*x)), ~"::"));
5113+
self.idents_to_str(path.idents));
51085114
self.record_def(expr.id, def);
51095115
}
51105116
None => {
5111-
let wrong_name =
5112-
connect(path.idents.map(
5113-
|x| self.session.str_of(*x)), ~"::") ;
5117+
let wrong_name = self.idents_to_str(path.idents);
51145118
if self.name_exists_in_scope_struct(wrong_name) {
51155119
self.session.span_err(expr.span,
51165120
fmt!("unresolved name: `%s`. \
@@ -5170,9 +5174,7 @@ impl Resolver {
51705174
self.session.span_err(
51715175
path.span,
51725176
fmt!("`%s` does not name a structure",
5173-
connect(path.idents.map(
5174-
|x| self.session.str_of(*x)),
5175-
~"::")));
5177+
self.idents_to_str(path.idents)));
51765178
}
51775179
}
51785180

@@ -5491,7 +5493,7 @@ impl Resolver {
54915493
// hit.
54925494
//
54935495

5494-
/// A somewhat inefficient routine to print out the name of a module.
5496+
/// A somewhat inefficient routine to obtain the name of a module.
54955497
fn module_to_str(module_: @Module) -> ~str {
54965498
let idents = DVec();
54975499
let mut current_module = module_;
@@ -5514,22 +5516,7 @@ impl Resolver {
55145516
if idents.len() == 0 {
55155517
return ~"???";
55165518
}
5517-
5518-
let mut string = ~"";
5519-
let mut i = idents.len() - 1;
5520-
loop {
5521-
if i < idents.len() - 1 {
5522-
string += ~"::";
5523-
}
5524-
string += self.session.str_of(idents.get_elt(i));
5525-
5526-
if i == 0 {
5527-
break;
5528-
}
5529-
i -= 1;
5530-
}
5531-
5532-
return string;
5519+
return self.idents_to_str(vec::reversed(idents.get()));
55335520
}
55345521

55355522
fn dump_module(module_: @Module) {

0 commit comments

Comments
 (0)