diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index 09910ce5cff..eabaffc8995 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -312,15 +312,15 @@ mod rt { let mut s = str::from_char(c); ret pad(cv, s, pad_nozero); } - fn conv_str(cv: conv, s: ~str) -> ~str { + fn conv_str(cv: conv, s: &str) -> ~str { // For strings, precision is the maximum characters // displayed let mut unpadded = alt cv.precision { - count_implied { s } + count_implied { s.to_unique() } count_is(max) { if max as uint < str::char_len(s) { str::substr(s, 0u, max as uint) - } else { s } + } else { s.to_unique() } } }; ret pad(cv, unpadded, pad_nozero); @@ -433,6 +433,14 @@ mod rt { } } +#[cfg(test)] +mod test { + #[test] + fn fmt_slice() { + let s = "abc"; + let _s = #fmt("%s", s); + } +} // Local Variables: // mode: rust; diff --git a/src/libcore/str.rs b/src/libcore/str.rs index b819ef0761e..e915bafafd3 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1944,6 +1944,7 @@ trait str_slice { fn to_upper() -> ~str; fn escape_default() -> ~str; fn escape_unicode() -> ~str; + fn to_unique() -> ~str; } /// Extension methods for strings @@ -2050,6 +2051,9 @@ impl extensions/& of str_slice for &str { /// Escape each char in `s` with char::escape_unicode. #[inline] fn escape_unicode() -> ~str { escape_unicode(self) } + + #[inline] + fn to_unique() -> ~str { self.slice(0, self.len()) } } #[cfg(test)]