Skip to content

Commit 27e1ac5

Browse files
committed
Merge pull request #4684 from erickt/incoming
core: convert ToStr::to_str to take explicit &self
2 parents 750f246 + 9adfa59 commit 27e1ac5

26 files changed

+88
-72
lines changed

src/libcore/num/f32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ pub pure fn to_str_digits(num: f32, dig: uint) -> ~str {
439439

440440
impl f32: to_str::ToStr {
441441
#[inline(always)]
442-
pure fn to_str() -> ~str { to_str_digits(self, 8) }
442+
pure fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
443443
}
444444

445445
impl f32: num::ToStrRadix {

src/libcore/num/f64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ pub pure fn to_str_digits(num: f64, dig: uint) -> ~str {
463463

464464
impl f64: to_str::ToStr {
465465
#[inline(always)]
466-
pure fn to_str() -> ~str { to_str_digits(self, 8) }
466+
pure fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
467467
}
468468

469469
impl f64: num::ToStrRadix {

src/libcore/num/float.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ pub pure fn to_str_digits(num: float, digits: uint) -> ~str {
206206
207207
impl float: to_str::ToStr {
208208
#[inline(always)]
209-
pure fn to_str() -> ~str { to_str_digits(self, 8) }
209+
pure fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
210210
}
211211
212212
impl float: num::ToStrRadix {

src/libcore/num/int-template.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ pub pure fn str(i: T) -> ~str { to_str(i) }
287287
288288
impl T : ToStr {
289289
#[inline(always)]
290-
pure fn to_str() -> ~str {
291-
to_str(self)
290+
pure fn to_str(&self) -> ~str {
291+
to_str(*self)
292292
}
293293
}
294294

src/libcore/num/uint-template.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ pub pure fn str(i: T) -> ~str { to_str(i) }
249249
250250
impl T : ToStr {
251251
#[inline(always)]
252-
pure fn to_str() -> ~str {
253-
to_str(self)
252+
pure fn to_str(&self) -> ~str {
253+
to_str(*self)
254254
}
255255
}
256256

src/libcore/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ impl Path {
368368
}
369369

370370
impl PosixPath : ToStr {
371-
pure fn to_str() -> ~str {
371+
pure fn to_str(&self) -> ~str {
372372
let mut s = ~"";
373373
if self.is_absolute {
374374
s += "/";
@@ -531,7 +531,7 @@ impl PosixPath : GenericPath {
531531

532532

533533
impl WindowsPath : ToStr {
534-
pure fn to_str() -> ~str {
534+
pure fn to_str(&self) -> ~str {
535535
let mut s = ~"";
536536
match self.host {
537537
Some(ref h) => { s += "\\\\"; s += *h; }

src/libcore/to_str.rs

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,52 +22,68 @@ use kinds::Copy;
2222
use str;
2323
use vec;
2424

25-
pub trait ToStr { pub pure fn to_str() -> ~str; }
25+
pub trait ToStr {
26+
pure fn to_str(&self) -> ~str;
27+
}
2628

2729
impl bool: ToStr {
2830
#[inline(always)]
29-
pure fn to_str() -> ~str { ::bool::to_str(self) }
31+
pure fn to_str(&self) -> ~str { ::bool::to_str(*self) }
3032
}
3133
impl (): ToStr {
3234
#[inline(always)]
33-
pure fn to_str() -> ~str { ~"()" }
35+
pure fn to_str(&self) -> ~str { ~"()" }
3436
}
3537
impl ~str: ToStr {
3638
#[inline(always)]
37-
pure fn to_str() -> ~str { copy self }
39+
pure fn to_str(&self) -> ~str { copy *self }
3840
}
3941
impl &str: ToStr {
4042
#[inline(always)]
41-
pure fn to_str() -> ~str { ::str::from_slice(self) }
43+
pure fn to_str(&self) -> ~str { ::str::from_slice(*self) }
4244
}
4345
impl @str: ToStr {
4446
#[inline(always)]
45-
pure fn to_str() -> ~str { ::str::from_slice(self) }
47+
pure fn to_str(&self) -> ~str { ::str::from_slice(*self) }
4648
}
4749

48-
impl<A: ToStr Copy, B: ToStr Copy> (A, B): ToStr {
50+
impl<A: ToStr, B: ToStr> (A, B): ToStr {
4951
#[inline(always)]
50-
pure fn to_str() -> ~str {
51-
let (a, b) = self;
52-
~"(" + a.to_str() + ~", " + b.to_str() + ~")"
52+
pure fn to_str(&self) -> ~str {
53+
// FIXME(#4760): this causes an llvm assertion
54+
//let &(ref a, ref b) = self;
55+
match *self {
56+
(ref a, ref b) => {
57+
~"(" + a.to_str() + ~", " + b.to_str() + ~")"
58+
}
59+
}
5360
}
5461
}
55-
impl<A: ToStr Copy, B: ToStr Copy, C: ToStr Copy> (A, B, C): ToStr {
62+
impl<A: ToStr, B: ToStr, C: ToStr> (A, B, C): ToStr {
5663
#[inline(always)]
57-
pure fn to_str() -> ~str {
58-
let (a, b, c) = self;
59-
~"(" + a.to_str() + ~", " + b.to_str() + ~", " + c.to_str() + ~")"
64+
pure fn to_str(&self) -> ~str {
65+
// FIXME(#4760): this causes an llvm assertion
66+
//let &(ref a, ref b, ref c) = self;
67+
match *self {
68+
(ref a, ref b, ref c) => {
69+
fmt!("(%s, %s, %s)",
70+
(*a).to_str(),
71+
(*b).to_str(),
72+
(*c).to_str()
73+
)
74+
}
75+
}
6076
}
6177
}
6278

6379
impl<A: ToStr> ~[A]: ToStr {
6480
#[inline(always)]
65-
pure fn to_str() -> ~str {
81+
pure fn to_str(&self) -> ~str {
6682
unsafe {
6783
// Bleh -- not really unsafe
6884
// push_str and push_char
6985
let mut acc = ~"[", first = true;
70-
for vec::each(self) |elt| {
86+
for self.each |elt| {
7187
unsafe {
7288
if first { first = false; }
7389
else { str::push_str(&mut acc, ~", "); }
@@ -82,11 +98,11 @@ impl<A: ToStr> ~[A]: ToStr {
8298
8399
impl<A: ToStr> @A: ToStr {
84100
#[inline(always)]
85-
pure fn to_str() -> ~str { ~"@" + (*self).to_str() }
101+
pure fn to_str(&self) -> ~str { ~"@" + (**self).to_str() }
86102
}
87103
impl<A: ToStr> ~A: ToStr {
88104
#[inline(always)]
89-
pure fn to_str() -> ~str { ~"~" + (*self).to_str() }
105+
pure fn to_str(&self) -> ~str { ~"~" + (**self).to_str() }
90106
}
91107

92108
#[cfg(test)]

src/librustc/middle/liveness.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ pub fn check_crate(tcx: ty::ctxt,
222222
}
223223

224224
impl LiveNode: to_str::ToStr {
225-
pure fn to_str() -> ~str { fmt!("ln(%u)", *self) }
225+
pure fn to_str(&self) -> ~str { fmt!("ln(%u)", **self) }
226226
}
227227

228228
impl Variable: to_str::ToStr {
229-
pure fn to_str() -> ~str { fmt!("v(%u)", *self) }
229+
pure fn to_str(&self) -> ~str { fmt!("v(%u)", **self) }
230230
}
231231

232232
// ______________________________________________________________________

src/librustc/middle/trans/closure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ pub struct EnvValue {
121121
}
122122

123123
pub impl EnvAction {
124-
fn to_str() -> ~str {
125-
match self {
124+
fn to_str(&self) -> ~str {
125+
match *self {
126126
EnvCopy => ~"EnvCopy",
127127
EnvMove => ~"EnvMove",
128128
EnvRef => ~"EnvRef"

src/librustc/middle/trans/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ pub impl block {
720720
fn ty_to_str(t: ty::t) -> ~str {
721721
ty_to_str(self.tcx(), t)
722722
}
723-
fn to_str() -> ~str {
723+
fn to_str(&self) -> ~str {
724724
match self.node_info {
725725
Some(node_info) => {
726726
fmt!("[block %d]", node_info.id)

0 commit comments

Comments
 (0)