Skip to content

Cleanup strs #7996

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 17 commits 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
2 changes: 1 addition & 1 deletion src/libextra/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mod test {

#[test]
fn test_interface_unwrap() {
let mut f = from_value(~"fail");
let f = from_value(~"fail");
assert_eq!(f.unwrap(), ~"fail");
}

Expand Down
42 changes: 21 additions & 21 deletions src/libextra/getopts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ pub fn opt_default(mm: &Matches, nm: &str, def: &str) -> Option<~str> {
let vals = opt_vals(mm, nm);
if vals.is_empty() { return None::<~str>; }
return match vals[0] { Val(ref s) => Some::<~str>((*s).clone()),
_ => Some::<~str>(str::to_owned(def)) }
_ => Some::<~str>(def.to_owned()) }
}

#[deriving(Eq)]
Expand Down Expand Up @@ -497,10 +497,10 @@ pub mod groups {
desc: &str, hint: &str) -> OptGroup {
let len = short_name.len();
assert!(len == 1 || len == 0);
return OptGroup { short_name: str::to_owned(short_name),
long_name: str::to_owned(long_name),
hint: str::to_owned(hint),
desc: str::to_owned(desc),
return OptGroup { short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: hint.to_owned(),
desc: desc.to_owned(),
hasarg: Yes,
occur: Req};
}
Expand All @@ -510,10 +510,10 @@ pub mod groups {
desc: &str, hint: &str) -> OptGroup {
let len = short_name.len();
assert!(len == 1 || len == 0);
return OptGroup {short_name: str::to_owned(short_name),
long_name: str::to_owned(long_name),
hint: str::to_owned(hint),
desc: str::to_owned(desc),
return OptGroup {short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: hint.to_owned(),
desc: desc.to_owned(),
hasarg: Yes,
occur: Optional};
}
Expand All @@ -523,10 +523,10 @@ pub mod groups {
desc: &str) -> OptGroup {
let len = short_name.len();
assert!(len == 1 || len == 0);
return OptGroup {short_name: str::to_owned(short_name),
long_name: str::to_owned(long_name),
return OptGroup {short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: ~"",
desc: str::to_owned(desc),
desc: desc.to_owned(),
hasarg: No,
occur: Optional};
}
Expand All @@ -536,10 +536,10 @@ pub mod groups {
desc: &str, hint: &str) -> OptGroup {
let len = short_name.len();
assert!(len == 1 || len == 0);
return OptGroup {short_name: str::to_owned(short_name),
long_name: str::to_owned(long_name),
hint: str::to_owned(hint),
desc: str::to_owned(desc),
return OptGroup {short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: hint.to_owned(),
desc: desc.to_owned(),
hasarg: Maybe,
occur: Optional};
}
Expand All @@ -552,10 +552,10 @@ pub mod groups {
desc: &str, hint: &str) -> OptGroup {
let len = short_name.len();
assert!(len == 1 || len == 0);
return OptGroup {short_name: str::to_owned(short_name),
long_name: str::to_owned(long_name),
hint: str::to_owned(hint),
desc: str::to_owned(desc),
return OptGroup {short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: hint.to_owned(),
desc: desc.to_owned(),
hasarg: Yes,
occur: Multi};
}
Expand Down Expand Up @@ -678,7 +678,7 @@ pub mod groups {
row
});

return str::to_owned(brief) +
return brief.to_owned() +
"\n\nOptions:\n" +
rows.collect::<~[~str]>().connect("\n") +
"\n\n";
Expand Down
10 changes: 5 additions & 5 deletions src/libextra/rl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub mod rustrt {

/// Add a line to history
pub unsafe fn add_history(line: &str) -> bool {
do str::as_c_str(line) |buf| {
do line.as_c_str |buf| {
rustrt::linenoiseHistoryAdd(buf) == 1 as c_int
}
}
Expand All @@ -44,21 +44,21 @@ pub unsafe fn set_history_max_len(len: int) -> bool {

/// Save line history to a file
pub unsafe fn save_history(file: &str) -> bool {
do str::as_c_str(file) |buf| {
do file.as_c_str |buf| {
rustrt::linenoiseHistorySave(buf) == 1 as c_int
}
}

/// Load line history from a file
pub unsafe fn load_history(file: &str) -> bool {
do str::as_c_str(file) |buf| {
do file.as_c_str |buf| {
rustrt::linenoiseHistoryLoad(buf) == 1 as c_int
}
}

/// Print out a prompt and then wait for input and return it
pub unsafe fn read(prompt: &str) -> Option<~str> {
do str::as_c_str(prompt) |buf| {
do prompt.as_c_str |buf| {
let line = rustrt::linenoise(buf);

if line.is_null() { None }
Expand All @@ -80,7 +80,7 @@ pub unsafe fn complete(cb: CompletionCb) {

unsafe {
do cb(str::raw::from_c_str(line)) |suggestion| {
do str::as_c_str(suggestion) |buf| {
do suggestion.as_c_str |buf| {
rustrt::linenoiseAddCompletion(completions, buf);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/terminfo/parm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ priv fn format(val: Param, op: FormatOp, flags: Flags) -> Result<~[u8],~str> {
String(s) => {
match op {
FormatString => {
let mut s = s.as_bytes_with_null_consume();
let mut s = s.to_bytes_with_null();
s.pop(); // remove the null
if flags.precision > 0 && flags.precision < s.len() {
s.truncate(flags.precision);
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ mod tests {

fn test(s: &str, format: &str) -> bool {
match strptime(s, format) {
Ok(ref tm) => tm.strftime(format) == str::to_owned(s),
Ok(ref tm) => tm.strftime(format) == s.to_owned(),
Err(e) => fail!(e)
}
}
Expand Down
32 changes: 17 additions & 15 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ pub fn WriteOutputFile(sess: Session,
OptLevel: c_int,
EnableSegmentedStacks: bool) {
unsafe {
do str::as_c_str(Triple) |Triple| {
do str::as_c_str(Feature) |Feature| {
do str::as_c_str(Output) |Output| {
do Triple.as_c_str |Triple| {
do Feature.as_c_str |Feature| {
do Output.as_c_str |Output| {
let result = llvm::LLVMRustWriteOutputFile(
PM,
M,
Expand Down Expand Up @@ -263,16 +263,16 @@ pub mod write {
output_type_bitcode => {
if opts.optimize != session::No {
let filename = output.with_filetype("no-opt.bc");
str::as_c_str(filename.to_str(), |buf| {
llvm::LLVMWriteBitcodeToFile(llmod, buf)
});
do filename.to_str().as_c_str |buf| {
llvm::LLVMWriteBitcodeToFile(llmod, buf);
}
}
}
_ => {
let filename = output.with_filetype("bc");
str::as_c_str(filename.to_str(), |buf| {
llvm::LLVMWriteBitcodeToFile(llmod, buf)
});
do filename.to_str().as_c_str |buf| {
llvm::LLVMWriteBitcodeToFile(llmod, buf);
}
}
}
}
Expand Down Expand Up @@ -333,9 +333,9 @@ pub mod write {
// Always output the bitcode file with --save-temps

let filename = output.with_filetype("opt.bc");
str::as_c_str(filename.to_str(), |buf| {
do filename.to_str().as_c_str |buf| {
llvm::LLVMWriteBitcodeToFile(llmod, buf)
});
};
// Save the assembly file if -S is used
if output_type == output_type_assembly {
WriteOutputFile(
Expand Down Expand Up @@ -391,13 +391,15 @@ pub mod write {

if output_type == output_type_llvm_assembly {
// Given options "-S --emit-llvm": output LLVM assembly
str::as_c_str(output.to_str(), |buf_o| {
llvm::LLVMRustAddPrintModulePass(pm.llpm, llmod, buf_o)});
do output.to_str().as_c_str |buf_o| {
llvm::LLVMRustAddPrintModulePass(pm.llpm, llmod, buf_o);
}
} else {
// If only a bitcode file is asked for by using the
// '--emit-llvm' flag, then output it here
str::as_c_str(output.to_str(),
|buf| llvm::LLVMWriteBitcodeToFile(llmod, buf) );
do output.to_str().as_c_str |buf| {
llvm::LLVMWriteBitcodeToFile(llmod, buf);
}
}

llvm::LLVMDisposeModule(llmod);
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/back/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::str;
use std::io;

use driver::session::{OptLevel, No, Less, Aggressive};
Expand Down Expand Up @@ -174,7 +173,7 @@ pub fn populate_pass_manager(sess: Session, pm: &mut PassManager, pass_list:&[~s
}

pub fn create_pass(name:&str) -> Option<PassRef> {
do str::as_c_str(name) |s| {
do name.as_c_str |s| {
unsafe {
let p = llvm::LLVMCreatePass(s);
if p.is_null() {
Expand Down
8 changes: 3 additions & 5 deletions src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use std::hashmap::HashMap;
use std::libc::{c_uint, c_ushort};
use std::option;
use std::str;

use middle::trans::type_::Type;

Expand Down Expand Up @@ -2287,10 +2286,9 @@ pub struct TargetData {
}

pub fn mk_target_data(string_rep: &str) -> TargetData {
let lltd =
str::as_c_str(string_rep, |buf| unsafe {
llvm::LLVMCreateTargetData(buf)
});
let lltd = do string_rep.as_c_str |buf| {
unsafe { llvm::LLVMCreateTargetData(buf) }
};

TargetData {
lltd: lltd,
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/metadata/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use std::option;
use std::os;
use std::result;
use std::str;

// A module for searching for libraries
// FIXME (#2658): I'm not happy how this module turned out. Should
Expand Down Expand Up @@ -83,7 +82,7 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
@FileSearchImpl {
sysroot: sysroot,
addl_lib_search_paths: addl_lib_search_paths,
target_triple: str::to_owned(target_triple)
target_triple: target_triple.to_owned()
} as @FileSearch
}

Expand All @@ -110,7 +109,7 @@ pub fn search<T>(filesearch: @FileSearch, pick: pick<T>) -> Option<T> {

pub fn relative_target_lib_path(target_triple: &str) -> Path {
Path(libdir()).push_many([~"rustc",
str::to_owned(target_triple),
target_triple.to_owned(),
libdir()])
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/metadata/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn libname(cx: &Context) -> (~str, ~str) {
os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
};

(str::to_owned(dll_prefix), str::to_owned(dll_suffix))
(dll_prefix.to_owned(), dll_suffix.to_owned())
}

fn find_library_crate_aux(
Expand Down Expand Up @@ -186,9 +186,9 @@ pub fn metadata_matches(extern_metas: &[@ast::MetaItem],
fn get_metadata_section(os: os,
filename: &Path) -> Option<@~[u8]> {
unsafe {
let mb = str::as_c_str(filename.to_str(), |buf| {
let mb = do filename.to_str().as_c_str |buf| {
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
});
};
if mb as int == 0 { return option::None::<@~[u8]>; }
let of = match mk_object_file(mb) {
option::Some(of) => of,
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1279,8 +1279,6 @@ pub fn compile_submatch(bcx: block,
assert!((m.len() > 0u || chk.is_some()));
let _icx = push_ctxt("match::compile_submatch");
let mut bcx = bcx;
let tcx = bcx.tcx();
let dm = tcx.def_map;
if m.len() == 0u {
Br(bcx, chk.get()());
return;
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/trans/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use middle::ty;

use middle::trans::type_::Type;

use std::str;
use syntax::ast;

// Take an inline assembly expression and splat it out via LLVM
Expand Down Expand Up @@ -123,8 +122,8 @@ pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block {
ast::asm_intel => lib::llvm::AD_Intel
};

let r = do str::as_c_str(ia.asm) |a| {
do str::as_c_str(constraints) |c| {
let r = do ia.asm.as_c_str |a| {
do constraints.as_c_str |c| {
InlineAsmCall(bcx, a, c, inputs, output, ia.volatile, ia.alignstack, dialect)
}
};
Expand Down
Loading