Skip to content

Commit c5d2639

Browse files
committed
libstd: Remove all uses of ~str from libstd
1 parent 86e54fb commit c5d2639

File tree

30 files changed

+238
-262
lines changed

30 files changed

+238
-262
lines changed

src/libcollections/bitv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ impl Bitv {
538538
* The resulting string has the same length as `self`, and each
539539
* character is either '0' or '1'.
540540
*/
541-
pub fn to_str(&self) -> ~str {
541+
pub fn to_str(&self) -> StrBuf {
542542
let mut rs = StrBuf::new();
543543
for i in self.iter() {
544544
if i {
@@ -547,7 +547,7 @@ impl Bitv {
547547
rs.push_char('0');
548548
}
549549
};
550-
rs.into_owned()
550+
rs
551551
}
552552

553553

src/libgetopts/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ pub fn getopts(args: &[StrBuf], optgrps: &[OptGroup]) -> Result {
661661
/// Derive a usage message from a set of long options.
662662
pub fn usage(brief: &str, opts: &[OptGroup]) -> StrBuf {
663663

664-
let desc_sep = "\n" + " ".repeat(24);
664+
let desc_sep = format!("\n{}", " ".repeat(24));
665665

666666
let mut rows = opts.iter().map(|optref| {
667667
let OptGroup{short_name: short_name,
@@ -713,7 +713,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> StrBuf {
713713
row.push_char(' ');
714714
}
715715
} else {
716-
row.push_str(desc_sep)
716+
row.push_str(desc_sep.as_slice())
717717
}
718718

719719
// Normalize desc to contain words separated by one space character
@@ -734,7 +734,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> StrBuf {
734734

735735
// FIXME: #5516 should be graphemes not codepoints
736736
// wrapped description
737-
row.push_str(desc_rows.connect(desc_sep));
737+
row.push_str(desc_rows.connect(desc_sep.as_slice()).as_slice());
738738

739739
row
740740
});
@@ -784,7 +784,11 @@ fn format_option(opt: &OptGroup) -> StrBuf {
784784
/// Derive a short one-line usage summary from a set of long options.
785785
pub fn short_usage(program_name: &str, opts: &[OptGroup]) -> StrBuf {
786786
let mut line = format_strbuf!("Usage: {} ", program_name);
787-
line.push_str(opts.iter().map(format_option).collect::<Vec<StrBuf>>().connect(" "));
787+
line.push_str(opts.iter()
788+
.map(format_option)
789+
.collect::<Vec<StrBuf>>()
790+
.connect(" ")
791+
.as_slice());
788792
line
789793
}
790794

src/librustc/back/link.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ pub mod write {
369369
sess.note(format!("{}", &cmd).as_slice());
370370
let mut note = prog.error.clone();
371371
note.push_all(prog.output.as_slice());
372-
sess.note(str::from_utf8(note.as_slice()).unwrap().to_owned());
372+
sess.note(str::from_utf8(note.as_slice()).unwrap()
373+
.as_slice());
373374
sess.abort_if_errors();
374375
}
375376
},
@@ -538,8 +539,8 @@ pub fn find_crate_id(attrs: &[ast::Attribute], out_filestem: &str) -> CrateId {
538539
match attr::find_crateid(attrs) {
539540
None => from_str(out_filestem).unwrap_or_else(|| {
540541
let mut s = out_filestem.chars().filter(|c| c.is_XID_continue());
541-
from_str(s.collect::<StrBuf>()
542-
.to_owned()).or(from_str("rust-out")).unwrap()
542+
from_str(s.collect::<StrBuf>().as_slice())
543+
.or(from_str("rust-out")).unwrap()
543544
}),
544545
Some(s) => s,
545546
}
@@ -698,7 +699,7 @@ pub fn exported_name(path: PathElems, hash: &str, vers: &str) -> StrBuf {
698699
// The version will get mangled to have a leading '_', but it makes more
699700
// sense to lead with a 'v' b/c this is a version...
700701
let vers = if vers.len() > 0 && !char::is_XID_start(vers.char_at(0)) {
701-
"v" + vers
702+
format!("v{}", vers)
702703
} else {
703704
vers.to_owned()
704705
};
@@ -1075,7 +1076,8 @@ fn link_natively(sess: &Session, trans: &CrateTranslation, dylib: bool,
10751076
sess.note(format!("{}", &cmd).as_slice());
10761077
let mut output = prog.error.clone();
10771078
output.push_all(prog.output.as_slice());
1078-
sess.note(str::from_utf8(output.as_slice()).unwrap().to_owned());
1079+
sess.note(str::from_utf8(output.as_slice()).unwrap()
1080+
.as_slice());
10791081
sess.abort_if_errors();
10801082
}
10811083
},

src/librustc/driver/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ Available lint options:
143143
for &(_, name) in lint_dict.iter() {
144144
max_key = cmp::max(name.len(), max_key);
145145
}
146-
fn padded(max: uint, s: &str) -> ~str {
147-
" ".repeat(max - s.len()) + s
146+
fn padded(max: uint, s: &str) -> StrBuf {
147+
format!("{}{}", " ".repeat(max - s.len()), s)
148148
}
149149
println!("\nAvailable lint checks:\n");
150150
println!(" {} {:7.7s} {}",
@@ -154,7 +154,7 @@ Available lint options:
154154
for (spec, name) in lint_dict.move_iter() {
155155
let name = name.replace("_", "-");
156156
println!(" {} {:7.7s} {}",
157-
padded(max_key, name),
157+
padded(max_key, name.as_slice()),
158158
lint::level_to_str(spec.default),
159159
spec.desc);
160160
}
@@ -400,11 +400,12 @@ fn monitor(f: proc():Send) {
400400

401401
let xs = [
402402
"the compiler hit an unexpected failure path. this is a bug.".to_owned(),
403-
"we would appreciate a bug report: " + BUG_REPORT_URL,
403+
format!("we would appreciate a bug report: {}",
404+
BUG_REPORT_URL),
404405
"run with `RUST_BACKTRACE=1` for a backtrace".to_owned(),
405406
];
406407
for note in xs.iter() {
407-
emitter.emit(None, *note, diagnostic::Note)
408+
emitter.emit(None, note.as_slice(), diagnostic::Note)
408409
}
409410

410411
match r.read_to_str() {

src/librustc/metadata/encoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ fn encode_visibility(ebml_w: &mut Encoder, visibility: Visibility) {
602602
Public => 'y',
603603
Inherited => 'i',
604604
};
605-
ebml_w.wr_str(str::from_char(ch));
605+
ebml_w.wr_str(str::from_char(ch).as_slice());
606606
ebml_w.end_tag();
607607
}
608608

@@ -848,7 +848,7 @@ fn encode_sized(ebml_w: &mut Encoder, sized: Sized) {
848848
DynSize => 'd',
849849
StaticSize => 's',
850850
};
851-
ebml_w.wr_str(str::from_char(ch));
851+
ebml_w.wr_str(str::from_char(ch).as_slice());
852852
ebml_w.end_tag();
853853
}
854854

@@ -1885,5 +1885,5 @@ pub fn encoded_ty(tcx: &ty::ctxt, t: ty::t) -> StrBuf {
18851885
tcx: tcx,
18861886
abbrevs: &RefCell::new(HashMap::new())
18871887
}, t);
1888-
str::from_utf8_owned(wr.get_ref().to_owned()).unwrap().to_strbuf()
1888+
str::from_utf8_owned(Vec::from_slice(wr.get_ref())).unwrap().to_strbuf()
18891889
}

src/librustc/metadata/loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ fn get_metadata_section_imp(os: Os, filename: &Path) -> Result<MetadataBlob, Str
552552
let name_len = llvm::LLVMRustGetSectionName(si.llsi, &mut name_buf);
553553
let name = str::raw::from_buf_len(name_buf as *u8, name_len as uint);
554554
debug!("get_metadata_section: name {}", name);
555-
if read_meta_section_name(os) == name {
555+
if read_meta_section_name(os).as_slice() == name.as_slice() {
556556
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
557557
let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;
558558
let mut found =

src/librustc/metadata/tydecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ fn parse_abi_set(st: &mut PState) -> abi::Abi {
452452
assert_eq!(next(st), '[');
453453
scan(st, |c| c == ']', |bytes| {
454454
let abi_str = str::from_utf8(bytes).unwrap().to_owned();
455-
abi::lookup(abi_str).expect(abi_str)
455+
abi::lookup(abi_str.as_slice()).expect(abi_str)
456456
})
457457
}
458458

src/librustc/middle/cfg/graphviz.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ fn replace_newline_with_backslash_l(s: StrBuf) -> StrBuf {
3737
// \l, not the line that follows; so, add \l at end of string
3838
// if not already present, ensuring last line gets left-aligned
3939
// as well.
40-
let mut last_two : Vec<_> = s.chars().rev().take(2).collect();
40+
let mut last_two: Vec<_> =
41+
s.as_slice().chars().rev().take(2).collect();
4142
last_two.reverse();
4243
if last_two.as_slice() != ['\\', 'l'] {
4344
s = s.append("\\l");

src/librustc/middle/trans/asm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ pub fn trans_inline_asm<'a>(bcx: &'a Block<'a>, ia: &ast::InlineAsm)
6767
StrBuf::from_str(constraints.iter()
6868
.map(|s| s.get().to_strbuf())
6969
.collect::<Vec<StrBuf>>()
70-
.connect(","));
70+
.connect(",")
71+
.as_slice());
7172

7273
let mut clobbers = getClobbers();
7374
if !ia.clobbers.get().is_empty() && !clobbers.is_empty() {

src/librustc/middle/trans/glue.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,10 @@ pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> tydesc_info {
438438
fn declare_generic_glue(ccx: &CrateContext, t: ty::t, llfnty: Type,
439439
name: &str) -> ValueRef {
440440
let _icx = push_ctxt("declare_generic_glue");
441-
let fn_nm = mangle_internal_name_by_type_and_seq(ccx, t, "glue_".to_owned() + name);
441+
let fn_nm = mangle_internal_name_by_type_and_seq(
442+
ccx,
443+
t,
444+
format!("glue_{}", name).as_slice());
442445
debug!("{} is for type {}", fn_nm, ppaux::ty_to_str(ccx.tcx(), t));
443446
let llfn = decl_cdecl_fn(ccx.llmod,
444447
fn_nm.as_slice(),

src/librustc/middle/trans/reflect.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ impl<'a, 'b> Reflector<'a, 'b> {
8787
pub fn visit(&mut self, ty_name: &str, args: &[ValueRef]) {
8888
let fcx = self.bcx.fcx;
8989
let tcx = self.bcx.tcx();
90-
let mth_idx = ty::method_idx(token::str_to_ident("visit_".to_owned() + ty_name),
90+
let mth_idx = ty::method_idx(token::str_to_ident(format!(
91+
"visit_{}", ty_name).as_slice()),
9192
self.visitor_methods.as_slice()).expect(
9293
format!("couldn't find visit method for {}", ty_name));
9394
let mth_ty =
@@ -154,7 +155,7 @@ impl<'a, 'b> Reflector<'a, 'b> {
154155
ty::ty_vec(ref mt, Some(sz)) => {
155156
let extra = (vec!(self.c_uint(sz))).append(self.c_size_and_align(t).as_slice());
156157
let extra = extra.append(self.c_mt(mt).as_slice());
157-
self.visit("evec_fixed".to_owned(), extra.as_slice())
158+
self.visit("evec_fixed", extra.as_slice())
158159
}
159160
ty::ty_vec(..) | ty::ty_str => fail!("unexpected unsized type"),
160161
// Should remove mt from box and uniq.
@@ -170,9 +171,9 @@ impl<'a, 'b> Reflector<'a, 'b> {
170171
ty::ty_vec(ref mt, None) => {
171172
let extra = Vec::new();
172173
let extra = extra.append(self.c_mt(mt).as_slice());
173-
self.visit("evec_uniq".to_owned(), extra.as_slice())
174+
self.visit("evec_uniq", extra.as_slice())
174175
}
175-
ty::ty_str => self.visit("estr_uniq".to_owned(), &[]),
176+
ty::ty_str => self.visit("estr_uniq", &[]),
176177
_ => {
177178
let extra = self.c_mt(&ty::mt {
178179
ty: typ,
@@ -191,9 +192,10 @@ impl<'a, 'b> Reflector<'a, 'b> {
191192
ty::ty_vec(ref mt, None) => {
192193
let (name, extra) = ("slice".to_owned(), Vec::new());
193194
let extra = extra.append(self.c_mt(mt).as_slice());
194-
self.visit("evec_".to_owned() + name, extra.as_slice())
195+
self.visit(format!("evec_{}", name).as_slice(),
196+
extra.as_slice())
195197
}
196-
ty::ty_str => self.visit("estr_slice".to_owned(), &[]),
198+
ty::ty_str => self.visit("estr_slice", &[]),
197199
_ => {
198200
let extra = self.c_mt(mt);
199201
self.visit("rptr", extra.as_slice())

src/librustc/util/ppaux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ pub fn ty_to_str(cx: &ctxt, typ: t) -> StrBuf {
327327
sig: &ty::FnSig) {
328328
s.push_char(bra);
329329
let strs: Vec<StrBuf> = sig.inputs.iter().map(|a| fn_input_to_str(cx, *a)).collect();
330-
s.push_str(strs.connect(", "));
330+
s.push_str(strs.connect(", ").as_slice());
331331
if sig.variadic {
332332
s.push_str(", ...");
333333
}

src/libserialize/json.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,9 @@ impl<'a> ::Encoder<io::IoError> for Encoder<'a> {
425425
}
426426
fn emit_f32(&mut self, v: f32) -> EncodeResult { self.emit_f64(v as f64) }
427427

428-
fn emit_char(&mut self, v: char) -> EncodeResult { self.emit_str(str::from_char(v)) }
428+
fn emit_char(&mut self, v: char) -> EncodeResult {
429+
self.emit_str(str::from_char(v).as_slice())
430+
}
429431
fn emit_str(&mut self, v: &str) -> EncodeResult {
430432
write!(self.wr, "{}", escape_str(v))
431433
}
@@ -614,9 +616,13 @@ impl<'a> ::Encoder<io::IoError> for PrettyEncoder<'a> {
614616
fn emit_f64(&mut self, v: f64) -> EncodeResult {
615617
write!(self.wr, "{}", f64::to_str_digits(v, 6u))
616618
}
617-
fn emit_f32(&mut self, v: f32) -> EncodeResult { self.emit_f64(v as f64) }
619+
fn emit_f32(&mut self, v: f32) -> EncodeResult {
620+
self.emit_f64(v as f64)
621+
}
618622

619-
fn emit_char(&mut self, v: char) -> EncodeResult { self.emit_str(str::from_char(v)) }
623+
fn emit_char(&mut self, v: char) -> EncodeResult {
624+
self.emit_str(str::from_char(v).as_slice())
625+
}
620626
fn emit_str(&mut self, v: &str) -> EncodeResult {
621627
write!(self.wr, "{}", escape_str(v))
622628
}

src/libstd/ascii.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,8 @@ unsafe fn str_map_bytes(string: StrBuf, map: &'static [u8]) -> StrBuf {
419419

420420
#[inline]
421421
unsafe fn str_copy_map_bytes(string: &str, map: &'static [u8]) -> StrBuf {
422-
let mut s = string.to_owned();
423-
for b in str::raw::as_owned_vec(&mut s).mut_iter() {
422+
let mut s = string.to_strbuf();
423+
for b in s.as_mut_bytes().mut_iter() {
424424
*b = map[*b as uint];
425425
}
426426
s.into_strbuf()

src/libstd/c_str.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -323,29 +323,6 @@ impl<'a> ToCStr for &'a str {
323323
}
324324
}
325325

326-
impl ToCStr for ~str {
327-
#[inline]
328-
fn to_c_str(&self) -> CString {
329-
self.as_bytes().to_c_str()
330-
}
331-
332-
#[inline]
333-
unsafe fn to_c_str_unchecked(&self) -> CString {
334-
self.as_bytes().to_c_str_unchecked()
335-
}
336-
337-
#[inline]
338-
fn with_c_str<T>(&self, f: |*libc::c_char| -> T) -> T {
339-
self.as_bytes().with_c_str(f)
340-
}
341-
342-
#[inline]
343-
unsafe fn with_c_str_unchecked<T>(&self, f: |*libc::c_char| -> T) -> T {
344-
self.as_bytes().with_c_str_unchecked(f)
345-
}
346-
}
347-
348-
349326
impl ToCStr for StrBuf {
350327
#[inline]
351328
fn to_c_str(&self) -> CString {

src/libstd/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
//! for which the [`slice`](slice/index.html) module defines many
4848
//! methods.
4949
//!
50-
//! UTF-8 strings, `~str` and `&str`, are built-in types, and the
51-
//! standard library defines methods for them on a variety of traits
52-
//! in the [`str`](str/index.html) module. Rust strings are immutable;
50+
//! `&str`, a UTF-8 string, is a built-in type, and the standard library
51+
//! defines methods for it on a variety of traits in the
52+
//! [`str`](str/index.html) module. Rust strings are immutable;
5353
//! use the `StrBuf` type defined in [`strbuf`](strbuf/index.html)
5454
//! for a mutable string builder.
5555
//!

0 commit comments

Comments
 (0)