Skip to content

Commit 624421a

Browse files
garethgareth
gareth
authored and
gareth
committedDec 29, 2012
Simplify idents_to_str and use it in more places.
1 parent d68954e commit 624421a

File tree

1 file changed

+10
-46
lines changed

1 file changed

+10
-46
lines changed
 

‎src/librustc/middle/resolve.rs

+10-46
Original file line numberDiff line numberDiff line change
@@ -2106,19 +2106,8 @@ impl Resolver {
21062106
}
21072107

21082108
fn idents_to_str(idents: ~[ident]) -> ~str {
2109-
// XXX: str::connect should do this.
2110-
let mut result = ~"";
2111-
let mut first = true;
2112-
for idents.each() |ident| {
2113-
if first {
2114-
first = false;
2115-
} else {
2116-
result += ~"::";
2117-
}
2118-
result += self.session.str_of(*ident);
2119-
}
2120-
// XXX: Shouldn't copy here. We need string builder functionality.
2121-
return result;
2109+
let ident_strs = idents.map(|&ident| self.session.str_of(ident));
2110+
return str::connect(ident_strs, "::");
21222111
}
21232112

21242113
fn import_directive_subclass_to_str(subclass: ImportDirectiveSubclass)
@@ -4524,17 +4513,14 @@ impl Resolver {
45244513
// Write the result into the def map.
45254514
debug!("(resolving type) writing resolution for `%s` \
45264515
(id %d)",
4527-
connect(path.idents.map(
4528-
|x| self.session.str_of(*x)), ~"::"),
4516+
self.idents_to_str(path.idents),
45294517
path_id);
45304518
self.record_def(path_id, def);
45314519
}
45324520
None => {
45334521
self.session.span_err
45344522
(ty.span, fmt!("use of undeclared type name `%s`",
4535-
connect(path.idents.map(
4536-
|x| self.session.str_of(*x)),
4537-
~"::")));
4523+
self.idents_to_str(path.idents)));
45384524
}
45394525
}
45404526
}
@@ -4728,9 +4714,7 @@ impl Resolver {
47284714
self.session.span_err(
47294715
path.span,
47304716
fmt!("`%s` does not name a structure",
4731-
connect(path.idents.map(
4732-
|x| self.session.str_of(*x)),
4733-
~"::")));
4717+
self.idents_to_str(path.idents)));
47344718
}
47354719
}
47364720
}
@@ -5126,14 +5110,11 @@ impl Resolver {
51265110
Some(def) => {
51275111
// Write the result into the def map.
51285112
debug!("(resolving expr) resolved `%s`",
5129-
connect(path.idents.map(
5130-
|x| self.session.str_of(*x)), ~"::"));
5113+
self.idents_to_str(path.idents));
51315114
self.record_def(expr.id, def);
51325115
}
51335116
None => {
5134-
let wrong_name =
5135-
connect(path.idents.map(
5136-
|x| self.session.str_of(*x)), ~"::") ;
5117+
let wrong_name = self.idents_to_str(path.idents);
51375118
if self.name_exists_in_scope_struct(wrong_name) {
51385119
self.session.span_err(expr.span,
51395120
fmt!("unresolved name: `%s`. \
@@ -5193,9 +5174,7 @@ impl Resolver {
51935174
self.session.span_err(
51945175
path.span,
51955176
fmt!("`%s` does not name a structure",
5196-
connect(path.idents.map(
5197-
|x| self.session.str_of(*x)),
5198-
~"::")));
5177+
self.idents_to_str(path.idents)));
51995178
}
52005179
}
52015180

@@ -5514,7 +5493,7 @@ impl Resolver {
55145493
// hit.
55155494
//
55165495

5517-
/// A somewhat inefficient routine to print out the name of a module.
5496+
/// A somewhat inefficient routine to obtain the name of a module.
55185497
fn module_to_str(module_: @Module) -> ~str {
55195498
let idents = DVec();
55205499
let mut current_module = module_;
@@ -5537,22 +5516,7 @@ impl Resolver {
55375516
if idents.len() == 0 {
55385517
return ~"???";
55395518
}
5540-
5541-
let mut string = ~"";
5542-
let mut i = idents.len() - 1;
5543-
loop {
5544-
if i < idents.len() - 1 {
5545-
string += ~"::";
5546-
}
5547-
string += self.session.str_of(idents.get_elt(i));
5548-
5549-
if i == 0 {
5550-
break;
5551-
}
5552-
i -= 1;
5553-
}
5554-
5555-
return string;
5519+
return self.idents_to_str(vec::reversed(idents.get()));
55565520
}
55575521

55585522
fn dump_module(module_: @Module) {

0 commit comments

Comments
 (0)
Please sign in to comment.