Skip to content

renamed str/vec::from_slice to str/vec::to_owned. #3356 #6389

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

Merged
merged 2 commits into from
May 11, 2013
Merged
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/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn is_test_ignored(config: config, testfile: &Path) -> bool {
return false;

fn xfail_target() -> ~str {
~"xfail-" + str::from_slice(os::SYSNAME)
~"xfail-" + str::to_owned(os::SYSNAME)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
was_expected = true;
}

if !was_expected && is_compiler_error_or_warning(str::from_slice(line)) {
if !was_expected && is_compiler_error_or_warning(str::to_owned(line)) {
fatal_ProcRes(fmt!("unexpected compiler error or warning: '%s'",
line),
ProcRes);
Expand Down Expand Up @@ -596,7 +596,7 @@ fn make_lib_name(config: config, auxfile: &Path, testfile: &Path) -> Path {

fn make_exe_name(config: config, testfile: &Path) -> Path {
Path(output_base_name(config, testfile).to_str() +
str::from_slice(os::EXE_SUFFIX))
str::to_owned(os::EXE_SUFFIX))
}

fn make_run_args(config: config, _props: TestProps, testfile: &Path) ->
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ impl<T:Reader> ReaderUtil for T {
fn read_lines(&self) -> ~[~str] {
do vec::build |push| {
for self.each_line |line| {
push(str::from_slice(line));
push(str::to_owned(line));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ fn dup2(src: c_int, dst: c_int) -> c_int {


pub fn dll_filename(base: &str) -> ~str {
return str::from_slice(DLL_PREFIX) + str::from_slice(base) +
str::from_slice(DLL_SUFFIX)
return str::to_owned(DLL_PREFIX) + str::to_owned(base) +
str::to_owned(DLL_SUFFIX)
}


Expand Down
16 changes: 8 additions & 8 deletions src/libcore/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ impl GenericPath for PosixPath {
fn with_filestem(&self, s: &str) -> PosixPath {
match self.filetype() {
None => self.with_filename(s),
Some(ref t) => self.with_filename(str::from_slice(s) + *t)
Some(ref t) => self.with_filename(str::to_owned(s) + *t)
}
}

Expand All @@ -488,7 +488,7 @@ impl GenericPath for PosixPath {
Some(ref s) => self.with_filename(*s)
}
} else {
let t = ~"." + str::from_slice(t);
let t = ~"." + str::to_owned(t);
match self.filestem() {
None => self.with_filename(t),
Some(ref s) => self.with_filename(*s + t)
Expand Down Expand Up @@ -621,7 +621,7 @@ impl GenericPath for WindowsPath {
None => {
host = None;
device = None;
rest = str::from_slice(s);
rest = str::to_owned(s);
}
}
}
Expand Down Expand Up @@ -694,7 +694,7 @@ impl GenericPath for WindowsPath {
fn with_filestem(&self, s: &str) -> WindowsPath {
match self.filetype() {
None => self.with_filename(s),
Some(ref t) => self.with_filename(str::from_slice(s) + *t)
Some(ref t) => self.with_filename(str::to_owned(s) + *t)
}
}

Expand All @@ -705,7 +705,7 @@ impl GenericPath for WindowsPath {
Some(ref s) => self.with_filename(*s)
}
} else {
let t = ~"." + str::from_slice(t);
let t = ~"." + str::to_owned(t);
match self.filestem() {
None => self.with_filename(t),
Some(ref s) =>
Expand Down Expand Up @@ -956,7 +956,7 @@ mod tests {
fn test_posix_paths() {
fn t(wp: &PosixPath, s: &str) {
let ss = wp.to_str();
let sss = str::from_slice(s);
let sss = str::to_owned(s);
if (ss != sss) {
debug!("got %s", ss);
debug!("expected %s", sss);
Expand Down Expand Up @@ -1014,7 +1014,7 @@ mod tests {
fn test_normalize() {
fn t(wp: &PosixPath, s: &str) {
let ss = wp.to_str();
let sss = str::from_slice(s);
let sss = str::to_owned(s);
if (ss != sss) {
debug!("got %s", ss);
debug!("expected %s", sss);
Expand Down Expand Up @@ -1077,7 +1077,7 @@ mod tests {
fn test_windows_paths() {
fn t(wp: &WindowsPath, s: &str) {
let ss = wp.to_str();
let sss = str::from_slice(s);
let sss = str::to_owned(s);
if (ss != sss) {
debug!("got %s", ss);
debug!("expected %s", sss);
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ impl<R: Rng> RngUtil for R {

/// Shuffle a vec
fn shuffle<T:Copy>(&mut self, values: &[T]) -> ~[T] {
let mut m = vec::from_slice(values);
let mut m = vec::to_owned(values);
self.shuffle_mut(m);
m
}
Expand Down
16 changes: 8 additions & 8 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ pub fn from_bytes_slice<'a>(vector: &'a [u8]) -> &'a str {

/// Copy a slice into a new unique str
#[inline(always)]
pub fn from_slice(s: &str) -> ~str {
pub fn to_owned(s: &str) -> ~str {
unsafe { raw::slice_bytes_owned(s, 0, len(s)) }
}

impl ToStr for ~str {
#[inline(always)]
fn to_str(&self) -> ~str { from_slice(*self) }
fn to_str(&self) -> ~str { to_owned(*self) }
}
impl<'self> ToStr for &'self str {
#[inline(always)]
fn to_str(&self) -> ~str { from_slice(*self) }
fn to_str(&self) -> ~str { to_owned(*self) }
}
impl ToStr for @str {
#[inline(always)]
fn to_str(&self) -> ~str { from_slice(*self) }
fn to_str(&self) -> ~str { to_owned(*self) }
}

/**
Expand Down Expand Up @@ -511,7 +511,7 @@ Section: Transforming strings
*/
pub fn to_bytes(s: &str) -> ~[u8] {
unsafe {
let mut v: ~[u8] = ::cast::transmute(from_slice(s));
let mut v: ~[u8] = ::cast::transmute(to_owned(s));
vec::raw::set_len(&mut v, len(s));
v
}
Expand Down Expand Up @@ -2141,7 +2141,7 @@ pub fn as_c_str<T>(s: &str, f: &fn(*libc::c_char) -> T) -> T {
// NB: len includes the trailing null.
assert!(len > 0);
if unsafe { *(ptr::offset(buf,len-1)) != 0 } {
as_c_str(from_slice(s), f)
as_c_str(to_owned(s), f)
} else {
f(buf as *libc::c_char)
}
Expand Down Expand Up @@ -2682,7 +2682,7 @@ impl<'self> StrSlice<'self> for &'self str {


#[inline]
fn to_owned(&self) -> ~str { from_slice(*self) }
fn to_owned(&self) -> ~str { to_owned(*self) }

#[inline]
fn to_managed(&self) -> @str {
Expand Down Expand Up @@ -2722,7 +2722,7 @@ impl OwnedStr for ~str {
impl Clone for ~str {
#[inline(always)]
fn clone(&self) -> ~str {
from_slice(*self)
to_owned(*self)
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub fn from_elem<T:Copy>(n_elts: uint, t: T) -> ~[T] {
}

/// Creates a new unique vector with the same contents as the slice
pub fn from_slice<T:Copy>(t: &[T]) -> ~[T] {
pub fn to_owned<T:Copy>(t: &[T]) -> ~[T] {
from_fn(t.len(), |i| t[i])
}

Expand Down Expand Up @@ -3451,19 +3451,19 @@ mod tests {
let mut results: ~[~[int]];

results = ~[];
for each_permutation(~[]) |v| { results.push(from_slice(v)); }
for each_permutation(~[]) |v| { results.push(to_owned(v)); }
assert!(results == ~[~[]]);

results = ~[];
for each_permutation(~[7]) |v| { results.push(from_slice(v)); }
for each_permutation(~[7]) |v| { results.push(to_owned(v)); }
assert!(results == ~[~[7]]);

results = ~[];
for each_permutation(~[1,1]) |v| { results.push(from_slice(v)); }
for each_permutation(~[1,1]) |v| { results.push(to_owned(v)); }
assert!(results == ~[~[1,1],~[1,1]]);

results = ~[];
for each_permutation(~[5,2,0]) |v| { results.push(from_slice(v)); }
for each_permutation(~[5,2,0]) |v| { results.push(to_owned(v)); }
assert!(results ==
~[~[5,2,0],~[5,0,2],~[2,5,0],~[2,0,5],~[0,5,2],~[0,2,5]]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libfuzzer/fuzzer.rc
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ pub fn check_variants_T<T:Copy>(crate: @ast::crate,
if L < 100 {
do under(uint::min(L, 20)) |i| {
error!("Replacing... #%?", uint::to_str(i));
let fname = str::from_slice(filename.to_str());
let fname = str::to_owned(filename.to_str());
do under(uint::min(L, 30)) |j| {
let fname = fname.to_str();
error!("With... %?", stringifier(things[j], intr));
Expand Down
2 changes: 1 addition & 1 deletion src/librust/rust.rc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn do_command(command: &Command, args: &[~str]) -> ValidUsage {
let (prog, prog_args) = (words.head(), words.tail());
let exitstatus = run::run_program(
*prog,
vec::append(vec::from_slice(prog_args), args)
vec::append(vec::to_owned(prog_args), args)
);
os::set_exit_status(exitstatus);
Valid
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,8 @@ pub fn output_dll_filename(os: session::os, lm: LinkMeta) -> ~str {
session::os_android => (android::DLL_PREFIX, android::DLL_SUFFIX),
session::os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
};
return str::from_slice(dll_prefix) + libname +
str::from_slice(dll_suffix);
return str::to_owned(dll_prefix) + libname +
str::to_owned(dll_suffix);
}

// If the user wants an exe generated we need to invoke
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ pub fn default_configuration(sess: Session, argv0: @~str, input: &input) ->
};

return ~[ // Target bindings.
attr::mk_word_item(@str::from_slice(os::FAMILY)),
attr::mk_word_item(@str::to_owned(os::FAMILY)),
mk(@~"target_os", @tos),
mk(@~"target_family", @str::from_slice(os::FAMILY)),
mk(@~"target_family", @str::to_owned(os::FAMILY)),
mk(@~"target_arch", @arch),
mk(@~"target_endian", @end),
mk(@~"target_word_size", @wordsz),
Expand Down Expand Up @@ -648,7 +648,7 @@ pub fn build_session_options(binary: @~str,
let linker_args = getopts::opt_strs(matches, ~"link-args").flat_map( |a| {
let mut args = ~[];
for str::each_split_char(*a, ' ') |arg| {
args.push(str::from_slice(arg));
args.push(str::to_owned(arg));
}
args
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ pub fn maybe_get_item_ast(intr: @ident_interner, cdata: cmd, tcx: ty::ctxt,
let item_doc = lookup_item(id, cdata.data);
let path = {
let item_path = item_path(intr, item_doc);
vec::from_slice(item_path.init())
vec::to_owned(item_path.init())
};
match decode_inlined_item(cdata, tcx, copy path, item_doc) {
Some(ref ii) => csearch::found((/*bad*/copy *ii)),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
//
// Should be:
//
// vec::from_slice(metadata_encoding_version) +
// vec::to_owned(metadata_encoding_version) +

let writer_bytes: &mut ~[u8] = wr.bytes;

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
@FileSearchImpl {
sysroot: sysroot,
addl_lib_search_paths: addl_lib_search_paths,
target_triple: str::from_slice(target_triple)
target_triple: str::to_owned(target_triple)
} as @FileSearch
}

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

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

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

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

fn find_library_crate_aux(
Expand Down
Loading