Skip to content

Commit 5633d46

Browse files
committed
libstd: Remove all uses of ~str from libstd
1 parent a9dd903 commit 5633d46

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
@@ -454,7 +454,10 @@ pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> tydesc_info {
454454
fn declare_generic_glue(ccx: &CrateContext, t: ty::t, llfnty: Type,
455455
name: &str) -> ValueRef {
456456
let _icx = push_ctxt("declare_generic_glue");
457-
let fn_nm = mangle_internal_name_by_type_and_seq(ccx, t, "glue_".to_owned() + name);
457+
let fn_nm = mangle_internal_name_by_type_and_seq(
458+
ccx,
459+
t,
460+
format!("glue_{}", name).as_slice());
458461
debug!("{} is for type {}", fn_nm, ppaux::ty_to_str(ccx.tcx(), t));
459462
let llfn = decl_cdecl_fn(ccx.llmod,
460463
fn_nm.as_slice(),

0 commit comments

Comments
 (0)