Skip to content

Commit 5da707f

Browse files
committed
---
yaml --- r: 39646 b: refs/heads/incoming c: 08d9c5b h: refs/heads/master v: v3
1 parent 094110c commit 5da707f

File tree

2 files changed

+36
-49
lines changed

2 files changed

+36
-49
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278
9-
refs/heads/incoming: 4dde334b474e51154f22d4e497fd66d1b0abb6b3
9+
refs/heads/incoming: 08d9c5be2f75bd034ca3e820fdad8e202b321307
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/librustc/middle/resolve.rs

Lines changed: 35 additions & 48 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.
@@ -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)