From 7ecddb2771922bcd0f117a3a3f681da9bcb8b70c Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Tue, 24 Jul 2012 12:11:29 -0700 Subject: [PATCH] More purity to make it easier to borrow strings in format strings. --- src/cargo/cargo.rs | 2 +- src/libcore/extfmt.rs | 8 ++++---- src/libcore/str.rs | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index 443d4dda020..87ec11c876e 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -1616,7 +1616,7 @@ fn cmd_sources(c: cargo) { if vec::len(c.opts.free) < 3u { for c.sources.each_value |v| { info(#fmt("%s (%s) via %s", - copy v.name, copy v.url, copy v.method)); + v.name, v.url, v.method)); } ret; } diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index eabaffc8995..ec5e9602e19 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -312,7 +312,7 @@ mod rt { let mut s = str::from_char(c); ret pad(cv, s, pad_nozero); } - fn conv_str(cv: conv, s: &str) -> ~str { + pure fn conv_str(cv: conv, s: &str) -> ~str { // For strings, precision is the maximum characters // displayed let mut unpadded = alt cv.precision { @@ -323,7 +323,7 @@ mod rt { } else { s.to_unique() } } }; - ret pad(cv, unpadded, pad_nozero); + ret unchecked { pad(cv, unpadded, pad_nozero) }; } fn conv_float(cv: conv, f: float) -> ~str { let (to_str, digits) = alt cv.precision { @@ -398,7 +398,7 @@ mod rt { pad_float { {might_zero_pad:true, signed:true } } pad_unsigned { {might_zero_pad:true, signed:false} } }; - fn have_precision(cv: conv) -> bool { + pure fn have_precision(cv: conv) -> bool { ret alt cv.precision { count_implied { false } _ { true } }; } let zero_padding = { @@ -428,7 +428,7 @@ mod rt { } ret padstr + s; } - fn have_flag(flags: u32, f: u32) -> bool { + pure fn have_flag(flags: u32, f: u32) -> bool { flags & f != 0 } } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index e915bafafd3..9b142adf165 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1934,7 +1934,7 @@ trait str_slice { fn is_whitespace() -> bool; fn is_alphanumeric() -> bool; pure fn len() -> uint; - fn slice(begin: uint, end: uint) -> ~str; + pure fn slice(begin: uint, end: uint) -> ~str; fn split(sepfn: fn(char) -> bool) -> ~[~str]; fn split_char(sep: char) -> ~[~str]; fn split_str(sep: &a/str) -> ~[~str]; @@ -1944,7 +1944,7 @@ trait str_slice { fn to_upper() -> ~str; fn escape_default() -> ~str; fn escape_unicode() -> ~str; - fn to_unique() -> ~str; + pure fn to_unique() -> ~str; } /// Extension methods for strings @@ -2013,7 +2013,7 @@ impl extensions/& of str_slice for &str { * beyond the last character of the string */ #[inline] - fn slice(begin: uint, end: uint) -> ~str { slice(self, begin, end) } + pure fn slice(begin: uint, end: uint) -> ~str { slice(self, begin, end) } /// Splits a string into substrings using a character function #[inline] fn split(sepfn: fn(char) -> bool) -> ~[~str] { split(self, sepfn) } @@ -2053,7 +2053,7 @@ impl extensions/& of str_slice for &str { fn escape_unicode() -> ~str { escape_unicode(self) } #[inline] - fn to_unique() -> ~str { self.slice(0, self.len()) } + pure fn to_unique() -> ~str { self.slice(0, self.len()) } } #[cfg(test)]