From b7da97504943c79185548881aab88d6a0e2118fd Mon Sep 17 00:00:00 2001 From: Youngsoo Son Date: Fri, 10 May 2013 18:38:54 +0900 Subject: [PATCH 1/2] renamed vec::from_slice to vec::to_owned --- src/libcore/rand.rs | 2 +- src/libcore/vec.rs | 10 +++++----- src/librust/rust.rc | 2 +- src/librustc/metadata/decoder.rs | 2 +- src/librustc/metadata/encoder.rs | 2 +- src/librustc/middle/check_match.rs | 22 +++++++++++----------- src/librustc/middle/trans/adt.rs | 2 +- src/librustc/middle/trans/cabi.rs | 8 ++++---- src/librustc/middle/ty.rs | 2 +- src/libstd/flatpipes.rs | 2 +- src/libstd/getopts.rs | 2 +- src/libstd/md4.rs | 2 +- src/libstd/num/bigint.rs | 2 +- src/libstd/stats.rs | 2 +- src/libsyntax/attr.rs | 2 +- src/libsyntax/ext/asm.rs | 2 +- src/libsyntax/ext/base.rs | 2 +- src/libsyntax/ext/log_syntax.rs | 2 +- src/libsyntax/ext/quote.rs | 2 +- src/libsyntax/ext/trace_macros.rs | 2 +- src/libsyntax/ext/tt/macro_rules.rs | 4 ++-- 21 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index f11840c95d5..672b71a1e9e 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -568,7 +568,7 @@ impl RngUtil for R { /// Shuffle a vec fn shuffle(&mut self, values: &[T]) -> ~[T] { - let mut m = vec::from_slice(values); + let mut m = vec::to_owned(values); self.shuffle_mut(m); m } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 3f3691670ef..eaf7723f006 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -166,7 +166,7 @@ pub fn from_elem(n_elts: uint, t: T) -> ~[T] { } /// Creates a new unique vector with the same contents as the slice -pub fn from_slice(t: &[T]) -> ~[T] { +pub fn to_owned(t: &[T]) -> ~[T] { from_fn(t.len(), |i| t[i]) } @@ -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]]); } diff --git a/src/librust/rust.rc b/src/librust/rust.rc index ff15fc12ff4..983ac1f1aaa 100644 --- a/src/librust/rust.rc +++ b/src/librust/rust.rc @@ -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 diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index fd35a4425d8..8ed2fe6378e 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -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)), diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 6c02ece9289..9014dc16fdd 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -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; diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 09232b5bba8..e9211cb0929 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -488,7 +488,7 @@ pub fn specialize(cx: @MatchCheckCtxt, match cx.tcx.def_map.find(&pat_id) { Some(&def_variant(_, id)) => { if variant(id) == *ctor_id { - Some(vec::from_slice(r.tail())) + Some(vec::to_owned(r.tail())) } else { None } @@ -507,7 +507,7 @@ pub fn specialize(cx: @MatchCheckCtxt, _ => fail!(~"type error") }; if match_ { - Some(vec::from_slice(r.tail())) + Some(vec::to_owned(r.tail())) } else { None } @@ -538,7 +538,7 @@ pub fn specialize(cx: @MatchCheckCtxt, _ => fail!(~"type error") }; if match_ { - Some(vec::from_slice(r.tail())) + Some(vec::to_owned(r.tail())) } else { None } @@ -548,7 +548,7 @@ pub fn specialize(cx: @MatchCheckCtxt, Some(args) => args, None => vec::from_elem(arity, wild()) }; - Some(vec::append(args, vec::from_slice(r.tail()))) + Some(vec::append(args, vec::to_owned(r.tail()))) } def_variant(_, _) => None, @@ -560,7 +560,7 @@ pub fn specialize(cx: @MatchCheckCtxt, Some(args) => new_args = args, None => new_args = vec::from_elem(arity, wild()) } - Some(vec::append(new_args, vec::from_slice(r.tail()))) + Some(vec::append(new_args, vec::to_owned(r.tail()))) } _ => None } @@ -578,7 +578,7 @@ pub fn specialize(cx: @MatchCheckCtxt, _ => wild() } }); - Some(vec::append(args, vec::from_slice(r.tail()))) + Some(vec::append(args, vec::to_owned(r.tail()))) } else { None } @@ -608,7 +608,7 @@ pub fn specialize(cx: @MatchCheckCtxt, _ => wild() } }); - Some(vec::append(args, vec::from_slice(r.tail()))) + Some(vec::append(args, vec::to_owned(r.tail()))) } } } @@ -627,21 +627,21 @@ pub fn specialize(cx: @MatchCheckCtxt, single => true, _ => fail!(~"type error") }; - if match_ { Some(vec::from_slice(r.tail())) } else { None } + if match_ { Some(vec::to_owned(r.tail())) } else { None } } pat_range(lo, hi) => { let (c_lo, c_hi) = match *ctor_id { val(ref v) => ((/*bad*/copy *v), (/*bad*/copy *v)), range(ref lo, ref hi) => ((/*bad*/copy *lo), (/*bad*/copy *hi)), - single => return Some(vec::from_slice(r.tail())), + single => return Some(vec::to_owned(r.tail())), _ => fail!(~"type error") }; let v_lo = eval_const_expr(cx.tcx, lo), v_hi = eval_const_expr(cx.tcx, hi); let match_ = compare_const_vals(&c_lo, &v_lo) >= 0 && compare_const_vals(&c_hi, &v_hi) <= 0; - if match_ { Some(vec::from_slice(r.tail())) } else { None } + if match_ { Some(vec::to_owned(r.tail())) } else { None } } pat_vec(before, slice, after) => { match *ctor_id { @@ -674,7 +674,7 @@ pub fn specialize(cx: @MatchCheckCtxt, } pub fn default(cx: @MatchCheckCtxt, r: &[@pat]) -> Option<~[@pat]> { - if is_wild(cx, r[0]) { Some(vec::from_slice(r.tail())) } + if is_wild(cx, r[0]) { Some(vec::to_owned(r.tail())) } else { None } } diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index 0ee2a2c4cb1..3274503e303 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -217,7 +217,7 @@ fn mk_struct(cx: @CrateContext, tys: &[ty::t], packed: bool) -> Struct { size: machine::llsize_of_alloc(cx, llty_rec) /*bad*/as u64, align: machine::llalign_of_min(cx, llty_rec) /*bad*/as u64, packed: packed, - fields: vec::from_slice(tys) + fields: vec::to_owned(tys) } } diff --git a/src/librustc/middle/trans/cabi.rs b/src/librustc/middle/trans/cabi.rs index d49e8e0969a..702d62f1363 100644 --- a/src/librustc/middle/trans/cabi.rs +++ b/src/librustc/middle/trans/cabi.rs @@ -71,8 +71,8 @@ pub impl FnType { let llretptr = GEPi(bcx, llargbundle, [0u, n]); let llretloc = Load(bcx, llretptr); llargvals = ~[llretloc]; - atys = vec::from_slice(atys.tail()); - attrs = vec::from_slice(attrs.tail()); + atys = vec::to_owned(atys.tail()); + attrs = vec::to_owned(attrs.tail()); } while i < n { @@ -137,8 +137,8 @@ pub impl FnType { let mut attrs = /*bad*/copy self.attrs; let mut j = 0u; let llretptr = if self.sret { - atys = vec::from_slice(atys.tail()); - attrs = vec::from_slice(attrs.tail()); + atys = vec::to_owned(atys.tail()); + attrs = vec::to_owned(attrs.tail()); j = 1u; get_param(llwrapfn, 0u) } else if self.ret_ty.cast { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index c31843870e8..449ecfe5dbf 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3813,7 +3813,7 @@ pub fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path { } ast_map::node_variant(ref variant, _, path) => { - vec::append_one(vec::from_slice(vec::init(*path)), + vec::append_one(vec::to_owned(vec::init(*path)), ast_map::path_name((*variant).node.name)) } diff --git a/src/libstd/flatpipes.rs b/src/libstd/flatpipes.rs index b712d6840ea..6547ff8eefb 100644 --- a/src/libstd/flatpipes.rs +++ b/src/libstd/flatpipes.rs @@ -442,7 +442,7 @@ pub mod flatteners { T: Decodable>( buf: &[u8]) -> T { - let buf = vec::from_slice(buf); + let buf = vec::to_owned(buf); let buf_reader = @BufReader::new(buf); let reader = buf_reader as @Reader; let mut deser: D = FromReader::from_reader(reader); diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index bc61f156c62..9b754c4ec5d 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -339,7 +339,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result { } i += 1; } - return Ok(Matches {opts: vec::from_slice(opts), + return Ok(Matches {opts: vec::to_owned(opts), vals: vals, free: free}); } diff --git a/src/libstd/md4.rs b/src/libstd/md4.rs index 24dd08c362e..71b62ca36a5 100644 --- a/src/libstd/md4.rs +++ b/src/libstd/md4.rs @@ -26,7 +26,7 @@ pub fn md4(msg: &[u8]) -> Quad { let orig_len: u64 = (vec::len(msg) * 8u) as u64; // pad message - let mut msg = vec::append(vec::from_slice(msg), ~[0x80u8]); + let mut msg = vec::append(vec::to_owned(msg), ~[0x80u8]); let mut bitlen = orig_len + 8u64; while (bitlen + 64u64) % 512u64 > 0u64 { msg.push(0u8); diff --git a/src/libstd/num/bigint.rs b/src/libstd/num/bigint.rs index 5762d863935..e64e97adfa3 100644 --- a/src/libstd/num/bigint.rs +++ b/src/libstd/num/bigint.rs @@ -541,7 +541,7 @@ impl BigUint { /// Creates and initializes an BigUint. #[inline(always)] pub fn from_slice(slice: &[BigDigit]) -> BigUint { - return BigUint::new(vec::from_slice(slice)); + return BigUint::new(vec::to_owned(slice)); } /// Creates and initializes an BigUint. diff --git a/src/libstd/stats.rs b/src/libstd/stats.rs index 6513a671ab3..25323b4e1db 100644 --- a/src/libstd/stats.rs +++ b/src/libstd/stats.rs @@ -52,7 +52,7 @@ impl<'self> Stats for &'self [f64] { fn median(self) -> f64 { assert!(self.len() != 0); - let mut tmp = vec::from_slice(self); + let mut tmp = vec::to_owned(self); sort::tim_sort(tmp); if tmp.len() & 1 == 0 { let m = tmp.len() / 2; diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index f4f0def2843..aebe5bbfc74 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -255,7 +255,7 @@ pub fn last_meta_item_list_by_name(items: ~[@ast::meta_item], name: &str) pub fn sort_meta_items(items: &[@ast::meta_item]) -> ~[@ast::meta_item] { // This is sort of stupid here, converting to a vec of mutables and back - let mut v = vec::from_slice(items); + let mut v = vec::to_owned(items); do std::sort::quick_sort(v) |ma, mb| { get_meta_item_name(*ma) <= get_meta_item_name(*mb) } diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index 53f40113532..00c178b6d7c 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -41,7 +41,7 @@ pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), - vec::from_slice(tts)); + vec::to_owned(tts)); let mut asm = ~""; let mut outputs = ~[]; diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index da8f87d3891..da18072f0e8 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -386,7 +386,7 @@ pub fn get_exprs_from_tts(cx: @ext_ctxt, tts: &[ast::token_tree]) -> ~[@ast::expr] { let p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), - vec::from_slice(tts)); + vec::to_owned(tts)); let mut es = ~[]; while *p.token != token::EOF { if es.len() != 0 { diff --git a/src/libsyntax/ext/log_syntax.rs b/src/libsyntax/ext/log_syntax.rs index 34d6978abdd..76d9a9420ce 100644 --- a/src/libsyntax/ext/log_syntax.rs +++ b/src/libsyntax/ext/log_syntax.rs @@ -22,7 +22,7 @@ pub fn expand_syntax_ext(cx: @ext_ctxt, cx.print_backtrace(); io::stdout().write_line( print::pprust::tt_to_str( - ast::tt_delim(vec::from_slice(tt)), + ast::tt_delim(vec::to_owned(tt)), cx.parse_sess().interner)); //trivial expression diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 917d11a0d23..34a37e4f6b4 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -669,7 +669,7 @@ fn expand_tts(cx: @ext_ctxt, let p = parse::new_parser_from_tts( cx.parse_sess(), cx.cfg(), - vec::from_slice(tts) + vec::to_owned(tts) ); *p.quote_depth += 1u; let tts = p.parse_all_token_trees(); diff --git a/src/libsyntax/ext/trace_macros.rs b/src/libsyntax/ext/trace_macros.rs index a29a0f33e0d..9660afb1bc0 100644 --- a/src/libsyntax/ext/trace_macros.rs +++ b/src/libsyntax/ext/trace_macros.rs @@ -25,7 +25,7 @@ pub fn expand_trace_macros(cx: @ext_ctxt, copy cx.parse_sess().span_diagnostic, cx.parse_sess().interner, None, - vec::from_slice(tt) + vec::to_owned(tt) ); let rdr = tt_rdr as @reader; let rust_parser = Parser( diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 39c3c63a9b7..e1de2f6381b 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -82,7 +82,7 @@ pub fn add_new_extension(cx: @ext_ctxt, io::println(fmt!("%s! { %s }", cx.str_of(name), print::pprust::tt_to_str( - ast::tt_delim(vec::from_slice(arg)), + ast::tt_delim(vec::to_owned(arg)), cx.parse_sess().interner))); } @@ -101,7 +101,7 @@ pub fn add_new_extension(cx: @ext_ctxt, s_d, itr, None, - vec::from_slice(arg) + vec::to_owned(arg) ) as @reader; match parse(cx.parse_sess(), cx.cfg(), arg_rdr, (*mtcs)) { success(named_matches) => { From 24ef88cee96de837370ec370ed4d1f3aa3530a20 Mon Sep 17 00:00:00 2001 From: Youngsoo Son Date: Fri, 10 May 2013 20:08:56 +0900 Subject: [PATCH 2/2] renamed str::from_slice to str::to_owned --- src/compiletest/header.rs | 2 +- src/compiletest/runtest.rs | 4 +- src/libcore/io.rs | 2 +- src/libcore/os.rs | 4 +- src/libcore/path.rs | 16 ++++---- src/libcore/str.rs | 16 ++++---- src/libfuzzer/fuzzer.rc | 2 +- src/librustc/back/link.rs | 4 +- src/librustc/driver/driver.rs | 6 +-- src/librustc/metadata/filesearch.rs | 4 +- src/librustc/metadata/loader.rs | 2 +- src/librustc/middle/trans/base.rs | 2 +- src/librustdoc/desc_to_brief_pass.rs | 6 +-- src/libstd/getopts.rs | 44 ++++++++++----------- src/libstd/net_ip.rs | 4 +- src/libstd/time.rs | 8 ++-- src/libsyntax/ext/quote.rs | 2 +- src/test/run-pass/struct-order-of-eval-1.rs | 2 +- src/test/run-pass/struct-order-of-eval-2.rs | 2 +- 19 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index 28bbbda9663..7e617aa0006 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -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) } } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 33f6dd36161..62c2612f2dd 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -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); @@ -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) -> diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 7fc2c2559c2..4ae7d1cdabd 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -711,7 +711,7 @@ impl 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)); } } } diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 574618026d9..3a5b18e3b57 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -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) } diff --git a/src/libcore/path.rs b/src/libcore/path.rs index a87fd90f4e2..ba95d1f4b5e 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -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) } } @@ -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) @@ -621,7 +621,7 @@ impl GenericPath for WindowsPath { None => { host = None; device = None; - rest = str::from_slice(s); + rest = str::to_owned(s); } } } @@ -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) } } @@ -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) => @@ -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); @@ -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); @@ -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); diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 5ec6471ac4a..fc0cc730dea 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -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) } } /** @@ -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 } @@ -2141,7 +2141,7 @@ pub fn as_c_str(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) } @@ -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 { @@ -2722,7 +2722,7 @@ impl OwnedStr for ~str { impl Clone for ~str { #[inline(always)] fn clone(&self) -> ~str { - from_slice(*self) + to_owned(*self) } } diff --git a/src/libfuzzer/fuzzer.rc b/src/libfuzzer/fuzzer.rc index 33e970c305a..c75dc2979f1 100644 --- a/src/libfuzzer/fuzzer.rc +++ b/src/libfuzzer/fuzzer.rc @@ -316,7 +316,7 @@ pub fn check_variants_T(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)); diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 3b5c90ec1f9..146b688ddc5 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -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 diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index cf77f81a492..d93a2ff59c0 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -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), @@ -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 }); diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index 7547f7f763a..6d712881a56 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -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 } @@ -99,7 +99,7 @@ pub fn search(filesearch: @FileSearch, pick: pick) -> Option { 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()]) } diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index 193f6fc8f0a..6605f17739c 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -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( diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 77a90e22150..391f68aeedc 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -104,7 +104,7 @@ impl get_insn_ctxt for @CrateContext { fn insn_ctxt(&self, s: &str) -> icx_popper { debug!("new insn_ctxt: %s", s); if self.sess.count_llvm_insns() { - self.stats.llvm_insn_ctxt.push(str::from_slice(s)); + self.stats.llvm_insn_ctxt.push(str::to_owned(s)); } icx_popper(*self) } diff --git a/src/librustdoc/desc_to_brief_pass.rs b/src/librustdoc/desc_to_brief_pass.rs index 40ff9b21829..278f77135f9 100644 --- a/src/librustdoc/desc_to_brief_pass.rs +++ b/src/librustdoc/desc_to_brief_pass.rs @@ -129,13 +129,13 @@ fn first_sentence_(s: &str) -> ~str { }; match idx { Some(idx) if idx > 2u => { - str::from_slice(str::slice(s, 0, idx - 1)) + str::to_owned(str::slice(s, 0, idx - 1)) } _ => { if str::ends_with(s, ~".") { - str::from_slice(s) + str::to_owned(s) } else { - str::from_slice(s) + str::to_owned(s) } } } diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index 9b754c4ec5d..f66b56381f0 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -106,7 +106,7 @@ pub struct Opt { } fn mkname(nm: &str) -> Name { - let unm = str::from_slice(nm); + let unm = str::to_owned(nm); return if nm.len() == 1u { Short(str::char_at(unm, 0u)) } else { Long(unm) }; @@ -441,7 +441,7 @@ pub fn opt_default(mm: &Matches, nm: &str, def: &str) -> Option<~str> { let vals = opt_vals(mm, nm); if vec::len::(vals) == 0u { return None::<~str>; } return match vals[0] { Val(copy s) => Some::<~str>(s), - _ => Some::<~str>(str::from_slice(def)) } + _ => Some::<~str>(str::to_owned(def)) } } #[deriving(Eq)] @@ -481,10 +481,10 @@ pub mod groups { desc: &str, hint: &str) -> OptGroup { let len = short_name.len(); assert!(len == 1 || len == 0); - return OptGroup { short_name: str::from_slice(short_name), - long_name: str::from_slice(long_name), - hint: str::from_slice(hint), - desc: str::from_slice(desc), + 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), hasarg: Yes, occur: Req}; } @@ -494,10 +494,10 @@ pub mod groups { desc: &str, hint: &str) -> OptGroup { let len = short_name.len(); assert!(len == 1 || len == 0); - return OptGroup {short_name: str::from_slice(short_name), - long_name: str::from_slice(long_name), - hint: str::from_slice(hint), - desc: str::from_slice(desc), + 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), hasarg: Yes, occur: Optional}; } @@ -507,10 +507,10 @@ pub mod groups { desc: &str) -> OptGroup { let len = short_name.len(); assert!(len == 1 || len == 0); - return OptGroup {short_name: str::from_slice(short_name), - long_name: str::from_slice(long_name), + return OptGroup {short_name: str::to_owned(short_name), + long_name: str::to_owned(long_name), hint: ~"", - desc: str::from_slice(desc), + desc: str::to_owned(desc), hasarg: No, occur: Optional}; } @@ -520,10 +520,10 @@ pub mod groups { desc: &str, hint: &str) -> OptGroup { let len = short_name.len(); assert!(len == 1 || len == 0); - return OptGroup {short_name: str::from_slice(short_name), - long_name: str::from_slice(long_name), - hint: str::from_slice(hint), - desc: str::from_slice(desc), + 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), hasarg: Maybe, occur: Optional}; } @@ -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::from_slice(short_name), - long_name: str::from_slice(long_name), - hint: str::from_slice(hint), - desc: str::from_slice(desc), + 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), hasarg: Yes, occur: Multi}; } @@ -648,7 +648,7 @@ pub mod groups { row }); - return str::from_slice(brief) + + return str::to_owned(brief) + ~"\n\nOptions:\n" + str::connect(rows, ~"\n") + ~"\n\n"; diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index 758e7a5e6ca..58775c5f2e4 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -225,7 +225,7 @@ pub mod v4 { let input_is_inaddr_none = result::get(&ip_rep_result).as_u32() == INADDR_NONE; - let new_addr = uv_ip4_addr(str::from_slice(ip), 22); + let new_addr = uv_ip4_addr(str::to_owned(ip), 22); let reformatted_name = uv_ip4_name(&new_addr); debug!("try_parse_addr: input ip: %s reparsed ip: %s", ip, reformatted_name); @@ -278,7 +278,7 @@ pub mod v6 { pub fn try_parse_addr(ip: &str) -> result::Result { unsafe { // need to figure out how to establish a parse failure.. - let new_addr = uv_ip6_addr(str::from_slice(ip), 22); + let new_addr = uv_ip6_addr(str::to_owned(ip), 22); let reparsed_name = uv_ip6_name(&new_addr); debug!("v6::try_parse_addr ip: '%s' reparsed '%s'", ip, reparsed_name); diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 31d8eb20a67..e731f679221 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -289,7 +289,7 @@ priv fn do_strptime(s: &str, format: &str) -> Result { let mut i = 0u; while i < digits { - let range = str::char_range_at(str::from_slice(ss), pos); + let range = str::char_range_at(str::to_owned(ss), pos); pos = range.next; match range.ch { @@ -628,7 +628,7 @@ priv fn do_strptime(s: &str, format: &str) -> Result { } } - do io::with_str_reader(str::from_slice(format)) |rdr| { + do io::with_str_reader(str::to_owned(format)) |rdr| { let mut tm = Tm { tm_sec: 0_i32, tm_min: 0_i32, @@ -840,7 +840,7 @@ priv fn do_strftime(format: &str, tm: &Tm) -> ~str { let mut buf = ~""; - do io::with_str_reader(str::from_slice(format)) |rdr| { + do io::with_str_reader(str::to_owned(format)) |rdr| { while !rdr.eof() { match rdr.read_char() { '%' => buf += parse_type(rdr.read_char(), tm), @@ -1022,7 +1022,7 @@ mod tests { fn test(s: &str, format: &str) -> bool { match strptime(s, format) { - Ok(ref tm) => tm.strftime(format) == str::from_slice(s), + Ok(ref tm) => tm.strftime(format) == str::to_owned(s), Err(copy e) => fail!(e) } } diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 34a37e4f6b4..b1ec9643f4e 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -123,7 +123,7 @@ pub mod rt { impl<'self> ToSource for &'self str { fn to_source(&self, _cx: @ext_ctxt) -> ~str { - let lit = dummy_spanned(ast::lit_str(@str::from_slice(*self))); + let lit = dummy_spanned(ast::lit_str(@str::to_owned(*self))); pprust::lit_to_str(@lit) } } diff --git a/src/test/run-pass/struct-order-of-eval-1.rs b/src/test/run-pass/struct-order-of-eval-1.rs index db7c73cbfc5..884459cf069 100644 --- a/src/test/run-pass/struct-order-of-eval-1.rs +++ b/src/test/run-pass/struct-order-of-eval-1.rs @@ -12,5 +12,5 @@ struct S { f0: ~str, f1: int } pub fn main() { let s = ~"Hello, world!"; - let _s = S { f0: str::from_slice(s), ..S { f0: s, f1: 23 } }; + let _s = S { f0: str::to_owned(s), ..S { f0: s, f1: 23 } }; } diff --git a/src/test/run-pass/struct-order-of-eval-2.rs b/src/test/run-pass/struct-order-of-eval-2.rs index 413f185659a..419c4ac3942 100644 --- a/src/test/run-pass/struct-order-of-eval-2.rs +++ b/src/test/run-pass/struct-order-of-eval-2.rs @@ -12,5 +12,5 @@ struct S { f0: ~str, f1: ~str } pub fn main() { let s = ~"Hello, world!"; - let _s = S { f1: str::from_slice(s), f0: s }; + let _s = S { f1: str::to_owned(s), f0: s }; }