Skip to content

Commit 6067106

Browse files
committed
libstd: Remove ~str from all libstd modules except fmt and str.
1 parent 082075d commit 6067106

File tree

204 files changed

+2110
-1498
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+2110
-1498
lines changed

src/compiletest/compiletest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub fn parse_config(args: Vec<StrBuf> ) -> Config {
9696
let args_ = args.tail();
9797
if args.get(1).as_slice() == "-h" || args.get(1).as_slice() == "--help" {
9898
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
99-
println!("{}", getopts::usage(message, groups.as_slice()));
99+
println!("{}", getopts::usage(message.as_slice(), groups.as_slice()));
100100
println!("");
101101
fail!()
102102
}
@@ -109,7 +109,7 @@ pub fn parse_config(args: Vec<StrBuf> ) -> Config {
109109

110110
if matches.opt_present("h") || matches.opt_present("help") {
111111
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
112-
println!("{}", getopts::usage(message, groups.as_slice()));
112+
println!("{}", getopts::usage(message.as_slice(), groups.as_slice()));
113113
println!("");
114114
fail!()
115115
}

src/compiletest/header.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,14 @@ fn iter_header(testfile: &Path, it: |&str| -> bool) -> bool {
157157
// module or function. This doesn't seem to be an optimization
158158
// with a warm page cache. Maybe with a cold one.
159159
let ln = ln.unwrap();
160-
if ln.starts_with("fn") || ln.starts_with("mod") {
160+
if ln.as_slice().starts_with("fn") ||
161+
ln.as_slice().starts_with("mod") {
161162
return true;
162-
} else { if !(it(ln.trim())) { return false; } }
163+
} else {
164+
if !(it(ln.as_slice().trim())) {
165+
return false;
166+
}
167+
}
163168
}
164169
return true;
165170
}

src/compiletest/runtest.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ fn run_debuginfo_lldb_test(config: &Config, props: &TestProps, testfile: &Path)
538538

539539
// Set breakpoints on every line that contains the string "#break"
540540
for line in breakpoint_lines.iter() {
541-
script_str.push_str(format!("breakpoint set --line {}\n", line));
541+
script_str.push_str(format!("breakpoint set --line {}\n",
542+
line).as_slice());
542543
}
543544

544545
// Append the other commands
@@ -620,18 +621,18 @@ fn parse_debugger_commands(file_path: &Path, debugger_prefix: &str)
620621
for line in reader.lines() {
621622
match line {
622623
Ok(line) => {
623-
if line.contains("#break") {
624+
if line.as_slice().contains("#break") {
624625
breakpoint_lines.push(counter);
625626
}
626627

627628
header::parse_name_value_directive(
628-
line,
629+
line.as_slice(),
629630
command_directive.to_strbuf()).map(|cmd| {
630631
commands.push(cmd)
631632
});
632633

633634
header::parse_name_value_directive(
634-
line,
635+
line.as_slice(),
635636
check_directive.to_strbuf()).map(|cmd| {
636637
check_lines.push(cmd)
637638
});

src/libfmt_macros/lib.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,13 @@ impl<'a> Parser<'a> {
274274
self.cur.next();
275275
}
276276
Some((_, other)) => {
277-
self.err(
278-
format!("expected `{}` but found `{}`", c, other));
277+
self.err(format!("expected `{}` but found `{}`",
278+
c,
279+
other).as_slice());
279280
}
280281
None => {
281-
self.err(
282-
format!("expected `{}` but string was terminated", c));
282+
self.err(format!("expected `{}` but string was terminated",
283+
c).as_slice());
283284
}
284285
}
285286
}
@@ -307,7 +308,8 @@ impl<'a> Parser<'a> {
307308
Some((_, c @ '#')) | Some((_, c @ '{')) |
308309
Some((_, c @ '\\')) | Some((_, c @ '}')) => { c }
309310
Some((_, c)) => {
310-
self.err(format!("invalid escape character `{}`", c));
311+
self.err(format!("invalid escape character `{}`",
312+
c).as_slice());
311313
c
312314
}
313315
None => {
@@ -459,7 +461,7 @@ impl<'a> Parser<'a> {
459461
return None;
460462
}
461463
method => {
462-
self.err(format!("unknown method: `{}`", method));
464+
self.err(format!("unknown method: `{}`", method).as_slice());
463465
return None;
464466
}
465467
}
@@ -526,7 +528,7 @@ impl<'a> Parser<'a> {
526528
let word = self.word();
527529
if word != "offset" {
528530
self.err(format!("expected `offset`, found `{}`",
529-
word));
531+
word).as_slice());
530532
} else {
531533
self.must_consume(':');
532534
match self.integer() {
@@ -566,7 +568,7 @@ impl<'a> Parser<'a> {
566568
"many" => Keyword(Many),
567569
word => {
568570
self.err(format!("unexpected plural selector `{}`",
569-
word));
571+
word).as_slice());
570572
if word == "" {
571573
break
572574
} else {

src/libgreen/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ macro_rules! rtassert (
4646

4747
macro_rules! rtabort (
4848
($($arg:tt)*) => ( {
49-
::macros::abort(format!($($arg)*));
49+
::macros::abort(format!($($arg)*).as_slice());
5050
} )
5151
)
5252

src/libhexfloat/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
147147
Some((err_pos, err_str)) => {
148148
let pos = expr.span.lo + syntax::codemap::Pos::from_uint(err_pos + 1);
149149
let span = syntax::codemap::mk_sp(pos,pos);
150-
cx.span_err(span, format!("invalid hex float literal in hexfloat!: {}", err_str));
150+
cx.span_err(span,
151+
format!("invalid hex float literal in hexfloat!: \
152+
{}",
153+
err_str).as_slice());
151154
return base::DummyResult::expr(sp);
152155
}
153156
_ => ()

src/liblog/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,10 @@ pub fn mod_enabled(level: u32, module: &str) -> bool {
302302
enabled(level, module, unsafe { (*DIRECTIVES).iter() })
303303
}
304304

305-
fn enabled(level: u32, module: &str,
306-
iter: slice::Items<directive::LogDirective>) -> bool {
305+
fn enabled(level: u32,
306+
module: &str,
307+
iter: slice::Items<directive::LogDirective>)
308+
-> bool {
307309
// Search for the longest match, the vector is assumed to be pre-sorted.
308310
for directive in iter.rev() {
309311
match directive.name {
@@ -322,7 +324,7 @@ fn enabled(level: u32, module: &str,
322324
/// `Once` primitive (and this function is called from that primitive).
323325
fn init() {
324326
let mut directives = match os::getenv("RUST_LOG") {
325-
Some(spec) => directive::parse_logging_spec(spec),
327+
Some(spec) => directive::parse_logging_spec(spec.as_slice()),
326328
None => Vec::new(),
327329
};
328330

src/libnative/io/addrinfo.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ fn get_error(_: c_int) -> IoError {
104104
#[cfg(not(windows))]
105105
fn get_error(s: c_int) -> IoError {
106106
use std::io;
107-
use std::str::raw::from_c_str;
108107

109-
let err_str = unsafe { from_c_str(gai_strerror(s)) };
108+
let err_str = unsafe {
109+
CString::new(gai_strerror(s), false).as_str().unwrap().to_strbuf()
110+
};
110111
IoError {
111112
kind: io::OtherIoError,
112113
desc: "unable to resolve host",

src/libnum/bigint.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ impl_to_biguint!(u32, FromPrimitive::from_u32)
604604
impl_to_biguint!(u64, FromPrimitive::from_u64)
605605

606606
impl ToStrRadix for BigUint {
607-
fn to_str_radix(&self, radix: uint) -> ~str {
607+
fn to_str_radix(&self, radix: uint) -> StrBuf {
608608
assert!(1 < radix && radix <= 16);
609609
let (base, max_len) = get_radix_base(radix);
610610
if base == BigDigit::base {
@@ -627,15 +627,17 @@ impl ToStrRadix for BigUint {
627627
return result;
628628
}
629629

630-
fn fill_concat(v: &[BigDigit], radix: uint, l: uint) -> ~str {
631-
if v.is_empty() { return "0".to_owned() }
630+
fn fill_concat(v: &[BigDigit], radix: uint, l: uint) -> StrBuf {
631+
if v.is_empty() {
632+
return "0".to_strbuf()
633+
}
632634
let mut s = StrBuf::with_capacity(v.len() * l);
633635
for n in v.iter().rev() {
634636
let ss = (*n as uint).to_str_radix(radix);
635637
s.push_str("0".repeat(l - ss.len()));
636-
s.push_str(ss);
638+
s.push_str(ss.as_slice());
637639
}
638-
s.as_slice().trim_left_chars('0').to_owned()
640+
s.as_slice().trim_left_chars('0').to_strbuf()
639641
}
640642
}
641643
}
@@ -1209,11 +1211,11 @@ impl_to_bigint!(u64, FromPrimitive::from_u64)
12091211

12101212
impl ToStrRadix for BigInt {
12111213
#[inline]
1212-
fn to_str_radix(&self, radix: uint) -> ~str {
1214+
fn to_str_radix(&self, radix: uint) -> StrBuf {
12131215
match self.sign {
12141216
Plus => self.data.to_str_radix(radix),
1215-
Zero => "0".to_owned(),
1216-
Minus => "-".to_owned() + self.data.to_str_radix(radix)
1217+
Zero => "0".to_strbuf(),
1218+
Minus => format_strbuf!("-{}", self.data.to_str_radix(radix)),
12171219
}
12181220
}
12191221
}

src/libnum/complex.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,15 @@ impl<T: fmt::Show + Num + Ord> fmt::Show for Complex<T> {
179179
}
180180

181181
impl<T: ToStrRadix + Num + Ord> ToStrRadix for Complex<T> {
182-
fn to_str_radix(&self, radix: uint) -> ~str {
182+
fn to_str_radix(&self, radix: uint) -> StrBuf {
183183
if self.im < Zero::zero() {
184-
format!("{}-{}i", self.re.to_str_radix(radix), (-self.im).to_str_radix(radix))
184+
format_strbuf!("{}-{}i",
185+
self.re.to_str_radix(radix),
186+
(-self.im).to_str_radix(radix))
185187
} else {
186-
format!("{}+{}i", self.re.to_str_radix(radix), self.im.to_str_radix(radix))
188+
format_strbuf!("{}+{}i",
189+
self.re.to_str_radix(radix),
190+
self.im.to_str_radix(radix))
187191
}
188192
}
189193
}

src/libnum/rational.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,10 @@ impl<T: fmt::Show> fmt::Show for Ratio<T> {
281281
}
282282
impl<T: ToStrRadix> ToStrRadix for Ratio<T> {
283283
/// Renders as `numer/denom` where the numbers are in base `radix`.
284-
fn to_str_radix(&self, radix: uint) -> ~str {
285-
format!("{}/{}", self.numer.to_str_radix(radix), self.denom.to_str_radix(radix))
284+
fn to_str_radix(&self, radix: uint) -> StrBuf {
285+
format_strbuf!("{}/{}",
286+
self.numer.to_str_radix(radix),
287+
self.denom.to_str_radix(radix))
286288
}
287289
}
288290

0 commit comments

Comments
 (0)