Skip to content

libstd: Remove ~str from all libstd modules except fmt and str. #14255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,14 @@ fn iter_header(testfile: &Path, it: |&str| -> bool) -> bool {
// module or function. This doesn't seem to be an optimization
// with a warm page cache. Maybe with a cold one.
let ln = ln.unwrap();
if ln.starts_with("fn") || ln.starts_with("mod") {
if ln.as_slice().starts_with("fn") ||
ln.as_slice().starts_with("mod") {
return true;
} else { if !(it(ln.trim())) { return false; } }
} else {
if !(it(ln.as_slice().trim())) {
return false;
}
}
}
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,18 +619,18 @@ fn parse_debugger_commands(file_path: &Path, debugger_prefix: &str)
for line in reader.lines() {
match line {
Ok(line) => {
if line.contains("#break") {
if line.as_slice().contains("#break") {
breakpoint_lines.push(counter);
}

header::parse_name_value_directive(
line,
line.as_slice(),
command_directive.to_strbuf()).map(|cmd| {
commands.push(cmd)
});

header::parse_name_value_directive(
line,
line.as_slice(),
check_directive.to_strbuf()).map(|cmd| {
check_lines.push(cmd)
});
Expand Down
8 changes: 5 additions & 3 deletions src/liblog/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,10 @@ pub fn mod_enabled(level: u32, module: &str) -> bool {
enabled(level, module, unsafe { (*DIRECTIVES).iter() })
}

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

Expand Down
5 changes: 3 additions & 2 deletions src/libnative/io/addrinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ fn get_error(_: c_int) -> IoError {
#[cfg(not(windows))]
fn get_error(s: c_int) -> IoError {
use std::io;
use std::str::raw::from_c_str;

let err_str = unsafe { from_c_str(gai_strerror(s)) };
let err_str = unsafe {
CString::new(gai_strerror(s), false).as_str().unwrap().to_strbuf()
};
IoError {
kind: io::OtherIoError,
desc: "unable to resolve host",
Expand Down
18 changes: 10 additions & 8 deletions src/libnum/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ impl_to_biguint!(u32, FromPrimitive::from_u32)
impl_to_biguint!(u64, FromPrimitive::from_u64)

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

fn fill_concat(v: &[BigDigit], radix: uint, l: uint) -> ~str {
if v.is_empty() { return "0".to_owned() }
fn fill_concat(v: &[BigDigit], radix: uint, l: uint) -> StrBuf {
if v.is_empty() {
return "0".to_strbuf()
}
let mut s = StrBuf::with_capacity(v.len() * l);
for n in v.iter().rev() {
let ss = (*n as uint).to_str_radix(radix);
s.push_str("0".repeat(l - ss.len()));
s.push_str(ss);
s.push_str(ss.as_slice());
}
s.as_slice().trim_left_chars('0').to_owned()
s.as_slice().trim_left_chars('0').to_strbuf()
}
}
}
Expand Down Expand Up @@ -1209,11 +1211,11 @@ impl_to_bigint!(u64, FromPrimitive::from_u64)

impl ToStrRadix for BigInt {
#[inline]
fn to_str_radix(&self, radix: uint) -> ~str {
fn to_str_radix(&self, radix: uint) -> StrBuf {
match self.sign {
Plus => self.data.to_str_radix(radix),
Zero => "0".to_owned(),
Minus => "-".to_owned() + self.data.to_str_radix(radix)
Zero => "0".to_strbuf(),
Minus => format_strbuf!("-{}", self.data.to_str_radix(radix)),
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/libnum/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,15 @@ impl<T: fmt::Show + Num + Ord> fmt::Show for Complex<T> {
}

impl<T: ToStrRadix + Num + Ord> ToStrRadix for Complex<T> {
fn to_str_radix(&self, radix: uint) -> ~str {
fn to_str_radix(&self, radix: uint) -> StrBuf {
if self.im < Zero::zero() {
format!("{}-{}i", self.re.to_str_radix(radix), (-self.im).to_str_radix(radix))
format_strbuf!("{}-{}i",
self.re.to_str_radix(radix),
(-self.im).to_str_radix(radix))
} else {
format!("{}+{}i", self.re.to_str_radix(radix), self.im.to_str_radix(radix))
format_strbuf!("{}+{}i",
self.re.to_str_radix(radix),
self.im.to_str_radix(radix))
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/libnum/rational.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,10 @@ impl<T: fmt::Show> fmt::Show for Ratio<T> {
}
impl<T: ToStrRadix> ToStrRadix for Ratio<T> {
/// Renders as `numer/denom` where the numbers are in base `radix`.
fn to_str_radix(&self, radix: uint) -> ~str {
format!("{}/{}", self.numer.to_str_radix(radix), self.denom.to_str_radix(radix))
fn to_str_radix(&self, radix: uint) -> StrBuf {
format_strbuf!("{}/{}",
self.numer.to_str_radix(radix),
self.denom.to_str_radix(radix))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libregex_macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn native(cx: &mut ExtCtxt, sp: codemap::Span, tts: &[ast::TokenTree])
let re = match Regex::new(regex.to_owned()) {
Ok(re) => re,
Err(err) => {
cx.span_err(sp, err.to_str());
cx.span_err(sp, err.to_str().as_slice());
return DummyResult::any(sp)
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl<'a> Archive<'a> {
if skip.iter().any(|s| *s == filename) { continue }
if filename.contains(".SYMDEF") { continue }

let filename = format!("r-{}-{}", name, filename);
let filename = format_strbuf!("r-{}-{}", name, filename);
let new_filename = file.with_filename(filename);
try!(fs::rename(file, &new_filename));
inputs.push(new_filename);
Expand All @@ -178,8 +178,8 @@ impl<'a> Archive<'a> {
};
// On Windows, static libraries sometimes show up as libfoo.a and other
// times show up as foo.lib
let oslibname = format!("{}{}.{}", osprefix, name, osext);
let unixlibname = format!("lib{}.a", name);
let oslibname = format_strbuf!("{}{}.{}", osprefix, name, osext);
let unixlibname = format_strbuf!("lib{}.a", name);

let mut rustpath = filesearch::rust_path();
rustpath.push(self.sess.target_filesearch().get_lib_path());
Expand Down
9 changes: 6 additions & 3 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ pub fn filename_for_input(sess: &Session, crate_type: config::CrateType,
let libname = output_lib_filename(id);
match crate_type {
config::CrateTypeRlib => {
out_filename.with_filename(format!("lib{}.rlib", libname))
out_filename.with_filename(format_strbuf!("lib{}.rlib", libname))
}
config::CrateTypeDylib => {
let (prefix, suffix) = match sess.targ_cfg.os {
Expand All @@ -825,10 +825,13 @@ pub fn filename_for_input(sess: &Session, crate_type: config::CrateType,
abi::OsAndroid => (loader::ANDROID_DLL_PREFIX, loader::ANDROID_DLL_SUFFIX),
abi::OsFreebsd => (loader::FREEBSD_DLL_PREFIX, loader::FREEBSD_DLL_SUFFIX),
};
out_filename.with_filename(format!("{}{}{}", prefix, libname, suffix))
out_filename.with_filename(format_strbuf!("{}{}{}",
prefix,
libname,
suffix))
}
config::CrateTypeStaticlib => {
out_filename.with_filename(format!("lib{}.a", libname))
out_filename.with_filename(format_strbuf!("lib{}.a", libname))
}
config::CrateTypeExecutable => out_filename.clone(),
}
Expand Down
8 changes: 5 additions & 3 deletions src/librustc/driver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,12 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {

let level_short = level_name.slice_chars(0, 1);
let level_short = level_short.to_ascii().to_upper().into_str();
let flags = matches.opt_strs(level_short).move_iter().collect::<Vec<_>>().append(
matches.opt_strs(level_name).as_slice());
let flags = matches.opt_strs(level_short.as_slice())
.move_iter()
.collect::<Vec<_>>()
.append(matches.opt_strs(level_name).as_slice());
for lint_name in flags.iter() {
let lint_name = lint_name.replace("-", "_");
let lint_name = lint_name.replace("-", "_").into_strbuf();
match lint_dict.find_equiv(&lint_name) {
None => {
early_error(format!("unknown {} flag: {}",
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,8 @@ fn print_flowgraph<W:io::Writer>(analysis: CrateAnalysis,
let m = "graphviz::render failed";
io::IoError {
detail: Some(match orig_detail {
None => m.into_owned(), Some(d) => format!("{}: {}", m, d)
None => m.into_strbuf(),
Some(d) => format_strbuf!("{}: {}", m, d)
}),
..ioerr
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ fn mk_test_module(cx: &TestCtxt) -> @ast::Item {
pub fn main() {
#![main]
use std::slice::Vector;
test::test_main_static_x(::std::os::args().as_slice(), TESTS);
test::test_main_static(::std::os::args().as_slice(), TESTS);
}
)).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn extract_crate_info(e: &Env, i: &ast::ViewItem) -> Option<CrateInfo> {
Some(id) => id
}
}
None => from_str(ident.get().to_str()).unwrap()
None => from_str(ident.get().to_str().as_slice()).unwrap()
};
Some(CrateInfo {
ident: ident.get().to_strbuf(),
Expand Down
5 changes: 4 additions & 1 deletion src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,10 @@ fn synthesize_crate_attrs(ecx: &EncodeContext,
attr::mk_attr(
attr::mk_name_value_item_str(
InternedString::new("crate_id"),
token::intern_and_get_ident(ecx.link_meta.crateid.to_str())))
token::intern_and_get_ident(ecx.link_meta
.crateid
.to_str()
.as_slice())))
}

let mut attrs = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ impl<'a> BorrowckCtxt<'a> {
}
mc::PositionalField(idx) => {
out.push_char('#'); // invent a notation here
out.push_str(idx.to_str());
out.push_str(idx.to_str().as_slice());
}
}
}
Expand Down
24 changes: 15 additions & 9 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, pats: Vec<@Pat> ) {
match ty::get(ty).sty {
ty::ty_bool => {
match *ctor {
val(const_bool(true)) => Some("true".to_owned()),
val(const_bool(false)) => Some("false".to_owned()),
val(const_bool(true)) => Some("true".to_strbuf()),
val(const_bool(false)) => Some("false".to_strbuf()),
_ => None
}
}
Expand All @@ -177,27 +177,33 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, pats: Vec<@Pat> ) {
let variants = ty::enum_variants(cx.tcx, id);

match variants.iter().find(|v| v.id == vid) {
Some(v) => Some(token::get_ident(v.name).get().to_str()),
Some(v) => {
Some(token::get_ident(v.name).get()
.to_str()
.into_strbuf())
}
None => {
fail!("check_exhaustive: bad variant in ctor")
}
}
}
ty::ty_vec(..) | ty::ty_rptr(..) => {
match *ctor {
vec(n) => Some(format!("vectors of length {}", n)),
vec(n) => {
Some(format_strbuf!("vectors of length {}", n))
}
_ => None
}
}
_ => None
}
}
};
let msg = "non-exhaustive patterns".to_owned() + match ext {
Some(ref s) => format!(": {} not covered", *s),
None => "".to_owned()
};
cx.tcx.sess.span_err(sp, msg);
let msg = format_strbuf!("non-exhaustive patterns{}", match ext {
Some(ref s) => format_strbuf!(": {} not covered", *s),
None => "".to_strbuf()
});
cx.tcx.sess.span_err(sp, msg.as_slice());
}

type matrix = Vec<Vec<@Pat> > ;
Expand Down
24 changes: 15 additions & 9 deletions src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,24 +506,30 @@ impl<'a> Context<'a> {
let mut note = None;
let msg = match src {
Default => {
format!("{}, \\#[{}({})] on by default", msg,
level_to_str(level), self.lint_to_str(lint))
format_strbuf!("{}, \\#[{}({})] on by default",
msg,
level_to_str(level),
self.lint_to_str(lint))
},
CommandLine => {
format!("{} [-{} {}]", msg,
match level {
warn => 'W', deny => 'D', forbid => 'F',
allow => fail!()
}, self.lint_to_str(lint).replace("_", "-"))
format_strbuf!("{} [-{} {}]",
msg,
match level {
warn => 'W',
deny => 'D',
forbid => 'F',
allow => fail!()
},
self.lint_to_str(lint).replace("_", "-"))
},
Node(src) => {
note = Some(src);
msg.to_str()
}
};
match level {
warn => { self.tcx.sess.span_warn(span, msg); }
deny | forbid => { self.tcx.sess.span_err(span, msg); }
warn => self.tcx.sess.span_warn(span, msg.as_slice()),
deny | forbid => self.tcx.sess.span_err(span, msg.as_slice()),
allow => fail!(),
}

Expand Down
7 changes: 5 additions & 2 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,11 @@ pub fn iter_structural_ty<'r,

for variant in (*variants).iter() {
let variant_cx =
fcx.new_temp_block("enum-iter-variant-".to_owned() +
variant.disr_val.to_str());
fcx.new_temp_block(
format_strbuf!("enum-iter-variant-{}",
variant.disr_val
.to_str()
.as_slice()).as_slice());
match adt::trans_case(cx, &*repr, variant.disr_val) {
_match::single_result(r) => {
AddCase(llswitch, r.val, variant_cx.llbb)
Expand Down
Loading