Revert "std: convert {vec,str}::to_owned to methods."

This fixes the strange random crashes in compile-fail tests.

This reverts commit 96cd61ad03.

Conflicts:
	src/librustc/driver/driver.rs
	src/libstd/str.rs
	src/libsyntax/ext/quote.rs
This commit is contained in:
Brian Anderson 2013-06-13 19:06:47 -07:00
parent b417bc8511
commit 7755018074
30 changed files with 104 additions and 90 deletions

View File

@ -450,7 +450,7 @@ pub mod flatteners {
T: Decodable<D>>( T: Decodable<D>>(
buf: &[u8]) buf: &[u8])
-> T { -> T {
let buf = buf.to_owned(); let buf = vec::to_owned(buf);
let buf_reader = @BufReader::new(buf); let buf_reader = @BufReader::new(buf);
let reader = buf_reader as @Reader; let reader = buf_reader as @Reader;
let mut deser: D = FromReader::from_reader(reader); let mut deser: D = FromReader::from_reader(reader);

View File

@ -345,7 +345,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
} }
i += 1; i += 1;
} }
return Ok(Matches {opts: opts.to_owned(), return Ok(Matches {opts: vec::to_owned(opts),
vals: vals, vals: vals,
free: free}); free: free});
} }
@ -447,7 +447,7 @@ pub fn opt_default(mm: &Matches, nm: &str, def: &str) -> Option<~str> {
let vals = opt_vals(mm, nm); let vals = opt_vals(mm, nm);
if vals.is_empty() { return None::<~str>; } if vals.is_empty() { return None::<~str>; }
return match vals[0] { Val(ref s) => Some::<~str>(copy *s), return match vals[0] { Val(ref s) => Some::<~str>(copy *s),
_ => Some::<~str>(def.to_owned()) } _ => Some::<~str>(str::to_owned(def)) }
} }
#[deriving(Eq)] #[deriving(Eq)]
@ -487,10 +487,10 @@ pub mod groups {
desc: &str, hint: &str) -> OptGroup { desc: &str, hint: &str) -> OptGroup {
let len = short_name.len(); let len = short_name.len();
assert!(len == 1 || len == 0); assert!(len == 1 || len == 0);
return OptGroup { short_name: short_name.to_owned(), return OptGroup { short_name: str::to_owned(short_name),
long_name: long_name.to_owned(), long_name: str::to_owned(long_name),
hint: hint.to_owned(), hint: str::to_owned(hint),
desc: desc.to_owned(), desc: str::to_owned(desc),
hasarg: Yes, hasarg: Yes,
occur: Req}; occur: Req};
} }
@ -500,10 +500,10 @@ pub mod groups {
desc: &str, hint: &str) -> OptGroup { desc: &str, hint: &str) -> OptGroup {
let len = short_name.len(); let len = short_name.len();
assert!(len == 1 || len == 0); assert!(len == 1 || len == 0);
return OptGroup {short_name: short_name.to_owned(), return OptGroup {short_name: str::to_owned(short_name),
long_name: long_name.to_owned(), long_name: str::to_owned(long_name),
hint: hint.to_owned(), hint: str::to_owned(hint),
desc: desc.to_owned(), desc: str::to_owned(desc),
hasarg: Yes, hasarg: Yes,
occur: Optional}; occur: Optional};
} }
@ -513,10 +513,10 @@ pub mod groups {
desc: &str) -> OptGroup { desc: &str) -> OptGroup {
let len = short_name.len(); let len = short_name.len();
assert!(len == 1 || len == 0); assert!(len == 1 || len == 0);
return OptGroup {short_name: short_name.to_owned(), return OptGroup {short_name: str::to_owned(short_name),
long_name: long_name.to_owned(), long_name: str::to_owned(long_name),
hint: ~"", hint: ~"",
desc: desc.to_owned(), desc: str::to_owned(desc),
hasarg: No, hasarg: No,
occur: Optional}; occur: Optional};
} }
@ -526,10 +526,10 @@ pub mod groups {
desc: &str, hint: &str) -> OptGroup { desc: &str, hint: &str) -> OptGroup {
let len = short_name.len(); let len = short_name.len();
assert!(len == 1 || len == 0); assert!(len == 1 || len == 0);
return OptGroup {short_name: short_name.to_owned(), return OptGroup {short_name: str::to_owned(short_name),
long_name: long_name.to_owned(), long_name: str::to_owned(long_name),
hint: hint.to_owned(), hint: str::to_owned(hint),
desc: desc.to_owned(), desc: str::to_owned(desc),
hasarg: Maybe, hasarg: Maybe,
occur: Optional}; occur: Optional};
} }
@ -542,10 +542,10 @@ pub mod groups {
desc: &str, hint: &str) -> OptGroup { desc: &str, hint: &str) -> OptGroup {
let len = short_name.len(); let len = short_name.len();
assert!(len == 1 || len == 0); assert!(len == 1 || len == 0);
return OptGroup {short_name: short_name.to_owned(), return OptGroup {short_name: str::to_owned(short_name),
long_name: long_name.to_owned(), long_name: str::to_owned(long_name),
hint: hint.to_owned(), hint: str::to_owned(hint),
desc: desc.to_owned(), desc: str::to_owned(desc),
hasarg: Yes, hasarg: Yes,
occur: Multi}; occur: Multi};
} }
@ -654,7 +654,7 @@ pub mod groups {
row row
}); });
return brief.to_owned() + return str::to_owned(brief) +
"\n\nOptions:\n" + "\n\nOptions:\n" +
rows.connect("\n") + rows.connect("\n") +
"\n\n"; "\n\n";

View File

@ -29,7 +29,7 @@ pub fn md4(msg: &[u8]) -> Quad {
let orig_len: u64 = (msg.len() * 8u) as u64; let orig_len: u64 = (msg.len() * 8u) as u64;
// pad message // pad message
let mut msg = vec::append(msg.to_owned(), [0x80u8]); let mut msg = vec::append(vec::to_owned(msg), [0x80u8]);
let mut bitlen = orig_len + 8u64; let mut bitlen = orig_len + 8u64;
while (bitlen + 64u64) % 512u64 > 0u64 { while (bitlen + 64u64) % 512u64 > 0u64 {
msg.push(0u8); msg.push(0u8);

View File

@ -564,7 +564,7 @@ impl BigUint {
/// Creates and initializes an BigUint. /// Creates and initializes an BigUint.
pub fn from_slice(slice: &[BigDigit]) -> BigUint { pub fn from_slice(slice: &[BigDigit]) -> BigUint {
return BigUint::new(slice.to_owned()); return BigUint::new(vec::to_owned(slice));
} }
/// Creates and initializes an BigUint. /// Creates and initializes an BigUint.

View File

@ -16,6 +16,7 @@ use core::iterator::*;
use core::f64; use core::f64;
use core::cmp; use core::cmp;
use core::num; use core::num;
use core::vec;
use sort; use sort;
// NB: this can probably be rewritten in terms of num::Num // NB: this can probably be rewritten in terms of num::Num
@ -56,7 +57,7 @@ impl<'self> Stats for &'self [f64] {
fn median(self) -> f64 { fn median(self) -> f64 {
assert!(self.len() != 0); assert!(self.len() != 0);
let mut tmp = self.to_owned(); let mut tmp = vec::to_owned(self);
sort::tim_sort(tmp); sort::tim_sort(tmp);
if tmp.len() & 1 == 0 { if tmp.len() & 1 == 0 {
let m = tmp.len() / 2; let m = tmp.len() / 2;

View File

@ -1029,7 +1029,7 @@ mod tests {
fn test(s: &str, format: &str) -> bool { fn test(s: &str, format: &str) -> bool {
match strptime(s, format) { match strptime(s, format) {
Ok(ref tm) => tm.strftime(format) == s.to_owned(), Ok(ref tm) => tm.strftime(format) == str::to_owned(s),
Err(e) => fail!(e) Err(e) => fail!(e)
} }
} }

View File

@ -328,7 +328,7 @@ pub fn check_variants_T<T:Copy>(crate: @ast::crate,
if L < 100 { if L < 100 {
do under(uint::min(L, 20)) |i| { do under(uint::min(L, 20)) |i| {
error!("Replacing... #%?", uint::to_str(i)); error!("Replacing... #%?", uint::to_str(i));
let fname = filename.to_str(); let fname = str::to_owned(filename.to_str());
do under(uint::min(L, 30)) |j| { do under(uint::min(L, 30)) |j| {
let fname = fname.to_str(); let fname = fname.to_str();
error!("With... %?", stringifier(things[j], intr)); error!("With... %?", stringifier(things[j], intr));

View File

@ -570,7 +570,7 @@ pub fn maybe_get_item_ast(cdata: cmd, tcx: ty::ctxt,
let item_doc = lookup_item(id, cdata.data); let item_doc = lookup_item(id, cdata.data);
let path = { let path = {
let item_path = item_path(item_doc); let item_path = item_path(item_doc);
item_path.init().to_owned() vec::to_owned(item_path.init())
}; };
match decode_inlined_item(cdata, tcx, copy path, item_doc) { match decode_inlined_item(cdata, tcx, copy path, item_doc) {
Some(ref ii) => csearch::found((/*bad*/copy *ii)), Some(ref ii) => csearch::found((/*bad*/copy *ii)),

View File

@ -1521,7 +1521,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
let writer_bytes: &mut ~[u8] = wr.bytes; let writer_bytes: &mut ~[u8] = wr.bytes;
metadata_encoding_version.to_owned() + vec::to_owned(metadata_encoding_version) +
flate::deflate_bytes(*writer_bytes) flate::deflate_bytes(*writer_bytes)
} }

View File

@ -13,6 +13,7 @@ use core::prelude::*;
use core::option; use core::option;
use core::os; use core::os;
use core::result; use core::result;
use core::str;
// A module for searching for libraries // A module for searching for libraries
// FIXME (#2658): I'm not happy how this module turned out. Should // FIXME (#2658): I'm not happy how this module turned out. Should
@ -80,7 +81,7 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
@FileSearchImpl { @FileSearchImpl {
sysroot: sysroot, sysroot: sysroot,
addl_lib_search_paths: addl_lib_search_paths, addl_lib_search_paths: addl_lib_search_paths,
target_triple: target_triple.to_owned() target_triple: str::to_owned(target_triple)
} as @FileSearch } as @FileSearch
} }
@ -106,7 +107,7 @@ pub fn search<T:Copy>(filesearch: @FileSearch, pick: pick<T>) -> Option<T> {
pub fn relative_target_lib_path(target_triple: &str) -> Path { pub fn relative_target_lib_path(target_triple: &str) -> Path {
Path(libdir()).push_many([~"rustc", Path(libdir()).push_many([~"rustc",
target_triple.to_owned(), str::to_owned(target_triple),
libdir()]) libdir()])
} }

View File

@ -80,7 +80,7 @@ fn libname(cx: &Context) -> (~str, ~str) {
os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX), os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
}; };
(dll_prefix.to_owned(), dll_suffix.to_owned()) (str::to_owned(dll_prefix), str::to_owned(dll_suffix))
} }
fn find_library_crate_aux( fn find_library_crate_aux(

View File

@ -495,7 +495,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
match cx.tcx.def_map.find(&pat_id) { match cx.tcx.def_map.find(&pat_id) {
Some(&def_variant(_, id)) => { Some(&def_variant(_, id)) => {
if variant(id) == *ctor_id { if variant(id) == *ctor_id {
Some(r.tail().to_owned()) Some(vec::to_owned(r.tail()))
} else { } else {
None None
} }
@ -533,7 +533,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
_ => fail!("type error") _ => fail!("type error")
}; };
if match_ { if match_ {
Some(r.tail().to_owned()) Some(vec::to_owned(r.tail()))
} else { } else {
None None
} }
@ -580,7 +580,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
_ => fail!("type error") _ => fail!("type error")
}; };
if match_ { if match_ {
Some(r.tail().to_owned()) Some(vec::to_owned(r.tail()))
} else { } else {
None None
} }
@ -590,7 +590,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
Some(args) => args, Some(args) => args,
None => vec::from_elem(arity, wild()) None => vec::from_elem(arity, wild())
}; };
Some(vec::append(args, r.tail().to_owned())) Some(vec::append(args, vec::to_owned(r.tail())))
} }
def_variant(_, _) => None, def_variant(_, _) => None,
@ -602,7 +602,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
Some(args) => new_args = args, Some(args) => new_args = args,
None => new_args = vec::from_elem(arity, wild()) None => new_args = vec::from_elem(arity, wild())
} }
Some(vec::append(new_args, r.tail().to_owned())) Some(vec::append(new_args, vec::to_owned(r.tail())))
} }
_ => None _ => None
} }
@ -620,7 +620,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
_ => wild() _ => wild()
} }
}); });
Some(vec::append(args, r.tail().to_owned())) Some(vec::append(args, vec::to_owned(r.tail())))
} else { } else {
None None
} }
@ -651,7 +651,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
_ => wild() _ => wild()
} }
}); });
Some(vec::append(args, r.tail().to_owned())) Some(vec::append(args, vec::to_owned(r.tail())))
} }
} }
} }
@ -687,14 +687,14 @@ pub fn specialize(cx: @MatchCheckCtxt,
single => true, single => true,
_ => fail!("type error") _ => fail!("type error")
}; };
if match_ { Some(r.tail().to_owned()) } else { None } if match_ { Some(vec::to_owned(r.tail())) } else { None }
} }
pat_range(lo, hi) => { pat_range(lo, hi) => {
let (c_lo, c_hi) = match *ctor_id { let (c_lo, c_hi) = match *ctor_id {
val(ref v) => ((/*bad*/copy *v), (/*bad*/copy *v)), val(ref v) => ((/*bad*/copy *v), (/*bad*/copy *v)),
range(ref lo, ref hi) => range(ref lo, ref hi) =>
((/*bad*/copy *lo), (/*bad*/copy *hi)), ((/*bad*/copy *lo), (/*bad*/copy *hi)),
single => return Some(r.tail().to_owned()), single => return Some(vec::to_owned(r.tail())),
_ => fail!("type error") _ => fail!("type error")
}; };
let v_lo = eval_const_expr(cx.tcx, lo); let v_lo = eval_const_expr(cx.tcx, lo);
@ -704,7 +704,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
let m2 = compare_const_vals(&c_hi, &v_hi); let m2 = compare_const_vals(&c_hi, &v_hi);
match (m1, m2) { match (m1, m2) {
(Some(val1), Some(val2)) if val1 >= 0 && val2 <= 0 => { (Some(val1), Some(val2)) if val1 >= 0 && val2 <= 0 => {
Some(r.tail().to_owned()) Some(vec::to_owned(r.tail()))
}, },
(Some(_), Some(_)) => None, (Some(_), Some(_)) => None,
_ => { _ => {
@ -745,7 +745,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
} }
pub fn default(cx: @MatchCheckCtxt, r: &[@pat]) -> Option<~[@pat]> { pub fn default(cx: @MatchCheckCtxt, r: &[@pat]) -> Option<~[@pat]> {
if is_wild(cx, r[0]) { Some(r.tail().to_owned()) } if is_wild(cx, r[0]) { Some(vec::to_owned(r.tail())) }
else { None } else { None }
} }

View File

@ -48,6 +48,8 @@ use core::iterator::IteratorUtil;
use core::container::Map; use core::container::Map;
use core::libc::c_ulonglong; use core::libc::c_ulonglong;
use core::option::{Option, Some, None}; use core::option::{Option, Some, None};
use core::str;
use core::vec;
use lib::llvm::{ValueRef, TypeRef, True, IntEQ, IntNE}; use lib::llvm::{ValueRef, TypeRef, True, IntEQ, IntNE};
use middle::trans::_match; use middle::trans::_match;
@ -217,7 +219,7 @@ fn mk_struct(cx: @CrateContext, tys: &[ty::t], packed: bool) -> Struct {
size: machine::llsize_of_alloc(cx, llty_rec) /*bad*/as u64, size: machine::llsize_of_alloc(cx, llty_rec) /*bad*/as u64,
align: machine::llalign_of_min(cx, llty_rec) /*bad*/as u64, align: machine::llalign_of_min(cx, llty_rec) /*bad*/as u64,
packed: packed, packed: packed,
fields: tys.to_owned() fields: vec::to_owned(tys)
} }
} }

View File

@ -113,7 +113,7 @@ impl get_insn_ctxt for @CrateContext {
fn insn_ctxt(&self, s: &str) -> icx_popper { fn insn_ctxt(&self, s: &str) -> icx_popper {
debug!("new insn_ctxt: %s", s); debug!("new insn_ctxt: %s", s);
if self.sess.count_llvm_insns() { if self.sess.count_llvm_insns() {
self.stats.llvm_insn_ctxt.push(s.to_owned()); self.stats.llvm_insn_ctxt.push(str::to_owned(s));
} }
icx_popper(*self) icx_popper(*self)
} }

View File

@ -3898,7 +3898,7 @@ pub fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path {
} }
ast_map::node_variant(ref variant, _, path) => { ast_map::node_variant(ref variant, _, path) => {
vec::append_one(path.init().to_owned(), vec::append_one(vec::to_owned(vec::init(*path)),
ast_map::path_name((*variant).node.name)) ast_map::path_name((*variant).node.name))
} }

View File

@ -131,13 +131,13 @@ fn first_sentence_(s: &str) -> ~str {
}); });
match idx { match idx {
Some(idx) if idx > 2u => { Some(idx) if idx > 2u => {
s.slice_to(idx - 1).to_owned() str::to_owned(s.slice(0, idx - 1))
} }
_ => { _ => {
if s.ends_with(".") { if s.ends_with(".") {
s.to_owned() str::to_owned(s)
} else { } else {
s.to_owned() str::to_owned(s)
} }
} }
} }

View File

@ -761,7 +761,7 @@ impl<T:Reader> ReaderUtil for T {
fn read_lines(&self) -> ~[~str] { fn read_lines(&self) -> ~[~str] {
do vec::build |push| { do vec::build |push| {
for self.each_line |line| { for self.each_line |line| {
push(line.to_owned()); push(str::to_owned(line));
} }
} }
} }

View File

@ -515,7 +515,7 @@ impl GenericPath for PosixPath {
fn with_filestem(&self, s: &str) -> PosixPath { fn with_filestem(&self, s: &str) -> PosixPath {
match self.filetype() { match self.filetype() {
None => self.with_filename(s), None => self.with_filename(s),
Some(ref t) => self.with_filename(s.to_owned() + *t), Some(ref t) => self.with_filename(str::to_owned(s) + *t),
} }
} }
@ -657,7 +657,7 @@ impl GenericPath for WindowsPath {
(None, None) => { (None, None) => {
host = None; host = None;
device = None; device = None;
rest = s.to_owned(); rest = str::to_owned(s);
} }
} }
@ -729,7 +729,7 @@ impl GenericPath for WindowsPath {
fn with_filestem(&self, s: &str) -> WindowsPath { fn with_filestem(&self, s: &str) -> WindowsPath {
match self.filetype() { match self.filetype() {
None => self.with_filename(s), None => self.with_filename(s),
Some(ref t) => self.with_filename(s.to_owned() + *t), Some(ref t) => self.with_filename(str::to_owned(s) + *t),
} }
} }
@ -983,7 +983,7 @@ mod tests {
fn test_posix_paths() { fn test_posix_paths() {
fn t(wp: &PosixPath, s: &str) { fn t(wp: &PosixPath, s: &str) {
let ss = wp.to_str(); let ss = wp.to_str();
let sss = s.to_owned(); let sss = str::to_owned(s);
if (ss != sss) { if (ss != sss) {
debug!("got %s", ss); debug!("got %s", ss);
debug!("expected %s", sss); debug!("expected %s", sss);
@ -1041,7 +1041,7 @@ mod tests {
fn test_normalize() { fn test_normalize() {
fn t(wp: &PosixPath, s: &str) { fn t(wp: &PosixPath, s: &str) {
let ss = wp.to_str(); let ss = wp.to_str();
let sss = s.to_owned(); let sss = str::to_owned(s);
if (ss != sss) { if (ss != sss) {
debug!("got %s", ss); debug!("got %s", ss);
debug!("expected %s", sss); debug!("expected %s", sss);
@ -1104,7 +1104,7 @@ mod tests {
fn test_windows_paths() { fn test_windows_paths() {
fn t(wp: &WindowsPath, s: &str) { fn t(wp: &WindowsPath, s: &str) {
let ss = wp.to_str(); let ss = wp.to_str();
let sss = s.to_owned(); let sss = str::to_owned(s);
if (ss != sss) { if (ss != sss) {
debug!("got %s", ss); debug!("got %s", ss);
debug!("expected %s", sss); debug!("expected %s", sss);

View File

@ -577,7 +577,7 @@ impl<R: Rng> RngUtil for R {
/// Shuffle a vec /// Shuffle a vec
fn shuffle<T:Copy>(&mut self, values: &[T]) -> ~[T] { fn shuffle<T:Copy>(&mut self, values: &[T]) -> ~[T] {
let mut m = values.to_owned(); let mut m = vec::to_owned(values);
self.shuffle_mut(m); self.shuffle_mut(m);
m m
} }

View File

@ -107,17 +107,23 @@ pub fn from_bytes_slice<'a>(vector: &'a [u8]) -> &'a str {
} }
} }
/// Copy a slice into a new unique str
#[inline(always)]
pub fn to_owned(s: &str) -> ~str {
unsafe { raw::slice_bytes_owned(s, 0, s.len()) }
}
impl ToStr for ~str { impl ToStr for ~str {
#[inline(always)] #[inline(always)]
fn to_str(&self) -> ~str { self.to_owned() } fn to_str(&self) -> ~str { to_owned(*self) }
} }
impl<'self> ToStr for &'self str { impl<'self> ToStr for &'self str {
#[inline(always)] #[inline(always)]
fn to_str(&self) -> ~str { self.to_owned() } fn to_str(&self) -> ~str { to_owned(*self) }
} }
impl ToStr for @str { impl ToStr for @str {
#[inline(always)] #[inline(always)]
fn to_str(&self) -> ~str { self.to_owned() } fn to_str(&self) -> ~str { to_owned(*self) }
} }
/** /**
@ -950,7 +956,7 @@ impl<'self> StrUtil for &'self str {
// NB: len includes the trailing null. // NB: len includes the trailing null.
assert!(len > 0); assert!(len > 0);
if unsafe { *(ptr::offset(buf,len-1)) != 0 } { if unsafe { *(ptr::offset(buf,len-1)) != 0 } {
self.to_owned().as_c_str(f) to_owned(self).as_c_str(f)
} else { } else {
f(buf as *libc::c_char) f(buf as *libc::c_char)
} }
@ -1204,9 +1210,7 @@ pub mod traits {
impl<'self> Add<&'self str,~str> for ~str { impl<'self> Add<&'self str,~str> for ~str {
#[inline(always)] #[inline(always)]
fn add(&self, rhs: & &'self str) -> ~str { fn add(&self, rhs: & &'self str) -> ~str {
let mut s = self.to_owned(); self.append((*rhs))
s.push_str(*rhs);
s
} }
} }
} }
@ -1665,11 +1669,8 @@ impl<'self> StrSlice<'self> for &'self str {
/// Copy a slice into a new unique str /// Copy a slice into a new unique str
#[inline] #[inline]
fn to_owned(&self) -> ~str { fn to_owned(&self) -> ~str { to_owned(*self) }
unsafe { raw::slice_bytes_owned(*self, 0, self.len()) }
}
/// Copy a slice into a new @str
#[inline] #[inline]
fn to_managed(&self) -> @str { fn to_managed(&self) -> @str {
let v = at_vec::from_fn(self.len() + 1, |i| { let v = at_vec::from_fn(self.len() + 1, |i| {
@ -2180,7 +2181,7 @@ impl OwnedStr for ~str {
impl Clone for ~str { impl Clone for ~str {
#[inline(always)] #[inline(always)]
fn clone(&self) -> ~str { fn clone(&self) -> ~str {
self.to_owned() to_owned(*self)
} }
} }
@ -3172,11 +3173,6 @@ mod tests {
assert_eq!("abc".to_managed(), @"abc"); assert_eq!("abc".to_managed(), @"abc");
assert_eq!("abcdef".slice(1, 5).to_managed(), @"bcde"); assert_eq!("abcdef".slice(1, 5).to_managed(), @"bcde");
} }
#[test]
fn test_to_owned() {
assert_eq!("abc".to_owned(), ~"abc");
assert_eq!("abcdef".slice(1, 5).to_owned(), ~"bcde");
}
#[test] #[test]
fn test_total_ord() { fn test_total_ord() {

View File

@ -171,6 +171,11 @@ 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 to_owned<T:Copy>(t: &[T]) -> ~[T] {
from_fn(t.len(), |i| t[i])
}
/// Creates a new vector with a capacity of `capacity` /// Creates a new vector with a capacity of `capacity`
pub fn with_capacity<T>(capacity: uint) -> ~[T] { pub fn with_capacity<T>(capacity: uint) -> ~[T] {
let mut vec = ~[]; let mut vec = ~[];
@ -1782,7 +1787,7 @@ pub trait CopyableVector<T> {
/// Extension methods for vectors /// Extension methods for vectors
impl<'self,T:Copy> CopyableVector<T> for &'self [T] { impl<'self,T:Copy> CopyableVector<T> for &'self [T] {
/// Creates a new unique vector with the same contents as the slice /// Returns a copy of `v`.
#[inline] #[inline]
fn to_owned(&self) -> ~[T] { fn to_owned(&self) -> ~[T] {
let mut result = ~[]; let mut result = ~[];
@ -1791,6 +1796,7 @@ impl<'self,T:Copy> CopyableVector<T> for &'self [T] {
result.push(copy *e); result.push(copy *e);
} }
result result
} }
} }
@ -3355,19 +3361,19 @@ mod tests {
let mut results: ~[~[int]]; let mut results: ~[~[int]];
results = ~[]; results = ~[];
for each_permutation([]) |v| { results.push(v.to_owned()); } for each_permutation([]) |v| { results.push(to_owned(v)); }
assert_eq!(results, ~[~[]]); assert_eq!(results, ~[~[]]);
results = ~[]; results = ~[];
for each_permutation([7]) |v| { results.push(v.to_owned()); } for each_permutation([7]) |v| { results.push(to_owned(v)); }
assert_eq!(results, ~[~[7]]); assert_eq!(results, ~[~[7]]);
results = ~[]; results = ~[];
for each_permutation([1,1]) |v| { results.push(v.to_owned()); } for each_permutation([1,1]) |v| { results.push(to_owned(v)); }
assert_eq!(results, ~[~[1,1],~[1,1]]); assert_eq!(results, ~[~[1,1],~[1,1]]);
results = ~[]; results = ~[];
for each_permutation([5,2,0]) |v| { results.push(v.to_owned()); } for each_permutation([5,2,0]) |v| { results.push(to_owned(v)); }
assert!(results == assert!(results ==
~[~[5,2,0],~[5,0,2],~[2,5,0],~[2,0,5],~[0,5,2],~[0,2,5]]); ~[~[5,2,0],~[5,0,2],~[2,5,0],~[2,0,5],~[0,5,2],~[0,2,5]]);
} }

View File

@ -259,7 +259,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] { 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 // This is sort of stupid here, converting to a vec of mutables and back
let mut v = items.to_owned(); let mut v = vec::to_owned(items);
do extra::sort::quick_sort(v) |ma, mb| { do extra::sort::quick_sort(v) |ma, mb| {
get_meta_item_name(*ma) <= get_meta_item_name(*mb) get_meta_item_name(*ma) <= get_meta_item_name(*mb)
} }

View File

@ -14,6 +14,7 @@
use core::prelude::*; use core::prelude::*;
use core::vec;
use ast; use ast;
use codemap::span; use codemap::span;
use ext::base; use ext::base;
@ -43,7 +44,7 @@ pub fn expand_asm(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
-> base::MacResult { -> base::MacResult {
let p = parse::new_parser_from_tts(cx.parse_sess(), let p = parse::new_parser_from_tts(cx.parse_sess(),
cx.cfg(), cx.cfg(),
tts.to_owned()); vec::to_owned(tts));
let mut asm = @""; let mut asm = @"";
let mut outputs = ~[]; let mut outputs = ~[];

View File

@ -10,6 +10,7 @@
use core::prelude::*; use core::prelude::*;
use core::vec;
use ast; use ast;
use ast::Name; use ast::Name;
use codemap; use codemap;
@ -366,7 +367,7 @@ pub fn get_exprs_from_tts(cx: @ExtCtxt, tts: &[ast::token_tree])
-> ~[@ast::expr] { -> ~[@ast::expr] {
let p = parse::new_parser_from_tts(cx.parse_sess(), let p = parse::new_parser_from_tts(cx.parse_sess(),
cx.cfg(), cx.cfg(),
tts.to_owned()); vec::to_owned(tts));
let mut es = ~[]; let mut es = ~[];
while *p.token != token::EOF { while *p.token != token::EOF {
if es.len() != 0 { if es.len() != 0 {

View File

@ -10,6 +10,7 @@
use core::prelude::*; use core::prelude::*;
use core::vec;
use ast; use ast;
use codemap; use codemap;
use ext::base::*; use ext::base::*;
@ -27,7 +28,7 @@ pub fn expand_syntax_ext(cx: @ExtCtxt,
cx.print_backtrace(); cx.print_backtrace();
io::stdout().write_line( io::stdout().write_line(
print::pprust::tt_to_str( print::pprust::tt_to_str(
ast::tt_delim(tt.to_owned()), ast::tt_delim(vec::to_owned(tt)),
get_ident_interner())); get_ident_interner()));
//trivial expression //trivial expression

View File

@ -10,6 +10,7 @@
use core::prelude::*; use core::prelude::*;
use core::vec;
use ast; use ast;
use codemap::{BytePos, Pos, span}; use codemap::{BytePos, Pos, span};
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
@ -38,6 +39,8 @@ pub mod rt {
use parse; use parse;
use print::pprust; use print::pprust;
use core::str;
pub use ast::*; pub use ast::*;
pub use parse::token::*; pub use parse::token::*;
pub use parse::new_parser_from_tts; pub use parse::new_parser_from_tts;
@ -655,7 +658,7 @@ fn expand_tts(cx: @ExtCtxt,
let p = parse::new_parser_from_tts( let p = parse::new_parser_from_tts(
cx.parse_sess(), cx.parse_sess(),
cx.cfg(), cx.cfg(),
tts.to_owned() vec::to_owned(tts)
); );
*p.quote_depth += 1u; *p.quote_depth += 1u;
let tts = p.parse_all_token_trees(); let tts = p.parse_all_token_trees();

View File

@ -10,6 +10,7 @@
use core::prelude::*; use core::prelude::*;
use core::vec;
use ast; use ast;
use codemap::span; use codemap::span;
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
@ -27,7 +28,7 @@ pub fn expand_trace_macros(cx: @ExtCtxt,
let tt_rdr = new_tt_reader( let tt_rdr = new_tt_reader(
copy cx.parse_sess().span_diagnostic, copy cx.parse_sess().span_diagnostic,
None, None,
tt.to_owned() vec::to_owned(tt)
); );
let rdr = tt_rdr as @reader; let rdr = tt_rdr as @reader;
let rust_parser = Parser( let rust_parser = Parser(

View File

@ -10,6 +10,7 @@
use core::prelude::*; use core::prelude::*;
use core::vec;
use ast::{ident, matcher_, matcher, match_tok, match_nonterminal, match_seq}; use ast::{ident, matcher_, matcher, match_tok, match_nonterminal, match_seq};
use ast::{tt_delim}; use ast::{tt_delim};
use ast; use ast;
@ -83,7 +84,7 @@ pub fn add_new_extension(cx: @ExtCtxt,
io::println(fmt!("%s! { %s }", io::println(fmt!("%s! { %s }",
cx.str_of(name), cx.str_of(name),
print::pprust::tt_to_str( print::pprust::tt_to_str(
ast::tt_delim(arg.to_owned()), ast::tt_delim(vec::to_owned(arg)),
get_ident_interner()))); get_ident_interner())));
} }
@ -100,7 +101,7 @@ pub fn add_new_extension(cx: @ExtCtxt,
let arg_rdr = new_tt_reader( let arg_rdr = new_tt_reader(
s_d, s_d,
None, None,
arg.to_owned() vec::to_owned(arg)
) as @reader; ) as @reader;
match parse(cx.parse_sess(), cx.cfg(), arg_rdr, *mtcs) { match parse(cx.parse_sess(), cx.cfg(), arg_rdr, *mtcs) {
success(named_matches) => { success(named_matches) => {

View File

@ -14,5 +14,5 @@ struct S { f0: ~str, f1: int }
pub fn main() { pub fn main() {
let s = ~"Hello, world!"; let s = ~"Hello, world!";
let _s = S { f0: s.to_owned(), ..S { f0: s, f1: 23 } }; let _s = S { f0: str::to_owned(s), ..S { f0: s, f1: 23 } };
} }

View File

@ -14,5 +14,5 @@ struct S { f0: ~str, f1: ~str }
pub fn main() { pub fn main() {
let s = ~"Hello, world!"; let s = ~"Hello, world!";
let _s = S { f1: s.to_owned(), f0: s }; let _s = S { f1: str::to_owned(s), f0: s };
} }