From 087c5032a86ad2f2433c6e5f9dcc597ec01de004 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 2 Sep 2012 15:37:15 -0700 Subject: [PATCH] core: deny(vecs_implicity_copyable) --- src/libcore/core.rc | 2 +- src/libcore/extfmt.rs | 14 +++++++------- src/libcore/int-template.rs | 2 +- src/libcore/io.rs | 3 +++ src/libcore/iter.rs | 2 +- src/libcore/os.rs | 5 ++++- src/libcore/path.rs | 4 ++-- src/libcore/run.rs | 8 ++++---- src/libcore/str.rs | 4 ++-- src/libcore/to_str.rs | 2 +- src/libcore/tuple.rs | 6 ++++-- src/libcore/vec.rs | 12 +++++++----- 12 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/libcore/core.rc b/src/libcore/core.rc index e6bb4730fae2c..0dcba1d202e0a 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -31,7 +31,7 @@ // Don't link to core. We are core. #[no_core]; -#[allow(vecs_implicitly_copyable)]; +#[deny(vecs_implicitly_copyable)]; export int, i8, i16, i32, i64; export uint, u8, u16, u32, u64; diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index 376a6bc2f56a1..8b92e7c183f37 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -86,7 +86,7 @@ mod ct { let mut pieces: ~[piece] = ~[]; let lim = str::len(s); let mut buf = ~""; - fn flush_buf(buf: ~str, &pieces: ~[piece]) -> ~str { + fn flush_buf(+buf: ~str, &pieces: ~[piece]) -> ~str { if str::len(buf) > 0u { let piece = piece_string(buf); vec::push(pieces, piece); @@ -109,7 +109,7 @@ mod ct { } else { buf = flush_buf(buf, pieces); let rs = parse_conversion(s, i, lim, error); - vec::push(pieces, rs.piece); + vec::push(pieces, copy rs.piece); i = rs.next; } } else { buf += curr; i += size; } @@ -148,7 +148,7 @@ mod ct { let ty = parse_type(s, prec.next, lim, error); return {piece: piece_conv({param: parm.param, - flags: flags.flags, + flags: copy flags.flags, width: width.count, precision: prec.count, ty: ty.ty}), @@ -177,12 +177,12 @@ mod ct { fn more_(f: flag, s: ~str, i: uint, lim: uint) -> {flags: ~[flag], next: uint} { let next = parse_flags(s, i + 1u, lim); - let rest = next.flags; + let rest = copy next.flags; let j = next.next; let curr: ~[flag] = ~[f]; return {flags: vec::append(curr, rest), next: j}; } - let more = |x| more_(x, s, i, lim); + let more = |x, copy s| more_(x, copy s, i, lim); let f = s[i]; return if f == '-' as u8 { more(flag_left_justify) @@ -404,14 +404,14 @@ mod rt { fn pad(cv: conv, &s: ~str, mode: pad_mode) -> ~str { let uwidth : uint = match cv.width { - count_implied => return s, + count_implied => return copy s, count_is(width) => { // FIXME: width should probably be uint (see Issue #1996) width as uint } }; let strlen = str::char_len(s); - if uwidth <= strlen { return s; } + if uwidth <= strlen { return copy s; } let mut padchar = ' '; let diff = uwidth - strlen; if have_flag(cv.flags, flag_left_justify) { diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs index bc080ac0d6301..757a64d0d7974 100644 --- a/src/libcore/int-template.rs +++ b/src/libcore/int-template.rs @@ -137,7 +137,7 @@ impl T: iter::TimesIx { * * buf - A byte buffer * * radix - The base of the number */ -fn parse_buf(buf: ~[u8], radix: uint) -> Option { +fn parse_buf(buf: &[u8], radix: uint) -> Option { if vec::len(buf) == 0u { return None; } let mut i = vec::len(buf) - 1u; let mut start = 0u; diff --git a/src/libcore/io.rs b/src/libcore/io.rs index f351ee77caab6..f5c4106c060ee 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -633,6 +633,7 @@ impl T : WriterUtil { fn write_u8(n: u8) { self.write(&[n]) } } +#[allow(non_implicitly_copyable_typarams)] fn file_writer(path: &Path, flags: ~[FileFlag]) -> Result { result::chain(mk_file_writer(path, flags), |w| result::Ok(w)) } @@ -726,6 +727,7 @@ fn seek_in_buf(offset: int, pos: uint, len: uint, whence: SeekStyle) -> return bpos as uint; } +#[allow(non_implicitly_copyable_typarams)] fn read_whole_file_str(file: &Path) -> Result<~str, ~str> { result::chain(read_whole_file(file), |bytes| { if str::is_utf8(bytes) { @@ -738,6 +740,7 @@ fn read_whole_file_str(file: &Path) -> Result<~str, ~str> { // FIXME (#2004): implement this in a low-level way. Going through the // abstractions is pointless. +#[allow(non_implicitly_copyable_typarams)] fn read_whole_file(file: &Path) -> Result<~[u8], ~str> { result::chain(file_reader(file), |rdr| { result::Ok(rdr.read_whole_stream()) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 91a4afc731831..e21c9b3c1bb4d 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -121,7 +121,7 @@ pure fn foldl>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B { } pure fn to_vec>(self: IA) -> ~[A] { - foldl::(self, ~[], |r, a| vec::append(r, ~[a])) + foldl::(self, ~[], |r, a| vec::append(copy r, ~[a])) } pure fn contains>(self: IA, x: A) -> bool { diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 4f9ee06145f91..2c5ad29116763 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -213,7 +213,7 @@ mod global_env { for vec::each(rustrt::rust_env_pairs()) |p| { let vs = str::splitn_char(p, '=', 1u); assert vec::len(vs) == 2u; - vec::push(pairs, (vs[0], vs[1])); + vec::push(pairs, (copy vs[0], copy vs[1])); } return pairs; } @@ -504,12 +504,14 @@ fn tmpdir() -> Path { } #[cfg(unix)] + #[allow(non_implicitly_copyable_typarams)] fn lookup() -> Path { option::get_default(getenv_nonempty("TMPDIR"), Path("/tmp")) } #[cfg(windows)] + #[allow(non_implicitly_copyable_typarams)] fn lookup() -> Path { option::get_default( option::or(getenv_nonempty("TMP"), @@ -609,6 +611,7 @@ fn make_dir(p: &Path, mode: c_int) -> bool { } /// Lists the contents of a directory +#[allow(non_implicitly_copyable_typarams)] fn list_dir(p: &Path) -> ~[~str] { #[cfg(unix)] diff --git a/src/libcore/path.rs b/src/libcore/path.rs index 7b1ac70009716..2151fc599e6cf 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -200,7 +200,7 @@ impl PosixPath : GenericPath { } pure fn push(s: &str) -> PosixPath { - let mut cs = self.components; + let mut cs = copy self.components; unchecked { vec::push(cs, move str::from_slice(s)); } return PosixPath { components: move cs, ..self } @@ -389,7 +389,7 @@ impl WindowsPath : GenericPath { } pure fn push(s: &str) -> WindowsPath { - let mut cs = self.components; + let mut cs = copy self.components; unchecked { vec::push(cs, move str::from_slice(s)); } return WindowsPath { components: move cs, ..self } diff --git a/src/libcore/run.rs b/src/libcore/run.rs index 1b101689ffb5e..9b9d5d81e0ee5 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -87,7 +87,7 @@ fn with_argv(prog: &str, args: &[~str], let mut argptrs = str::as_c_str(prog, |b| ~[b]); let mut tmps = ~[]; for vec::each(args) |arg| { - let t = @arg; + let t = @copy arg; vec::push(tmps, t); vec::push_all(argptrs, str::as_c_str(*t, |b| ~[b])); } @@ -106,7 +106,7 @@ fn with_envp(env: &Option<~[(~str,~str)]>, let mut ptrs = ~[]; for vec::each(es) |e| { - let (k,v) = e; + let (k,v) = copy e; let t = @(fmt!("%s=%s", k, v)); vec::push(tmps, t); vec::push_all(ptrs, str::as_c_str(*t, |b| ~[b])); @@ -315,10 +315,10 @@ fn program_output(prog: &str, args: &[~str]) -> let stream = comm::recv(p); match stream { (1, s) => { - outs = s; + outs = copy s; } (2, s) => { - errs = s; + errs = copy s; } (n, _) => { fail(fmt!("program_output received an unexpected file \ diff --git a/src/libcore/str.rs b/src/libcore/str.rs index bbebfd12bc837..861a603e1706d 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -605,7 +605,7 @@ pure fn lines(s: &str) -> ~[~str] { split_char(s, '\n') } pure fn lines_any(s: &str) -> ~[~str] { vec::map(lines(s), |s| { let l = len(s); - let mut cp = s; + let mut cp = copy s; if l > 0u && s[l - 1u] == '\r' as u8 { unsafe { unsafe::set_len(cp, l - 1u); } } @@ -2068,7 +2068,7 @@ impl ~str: UniqueStr { impl ~str: add<&str,~str> { #[inline(always)] pure fn add(rhs: &str) -> ~str { - append(self, rhs) + append(copy self, rhs) } } diff --git a/src/libcore/to_str.rs b/src/libcore/to_str.rs index 7d35b2536fa06..63e0f366c5365 100644 --- a/src/libcore/to_str.rs +++ b/src/libcore/to_str.rs @@ -44,7 +44,7 @@ impl (): ToStr { fn to_str() -> ~str { ~"()" } } impl ~str: ToStr { - fn to_str() -> ~str { self } + fn to_str() -> ~str { copy self } } impl &str: ToStr { fn to_str() -> ~str { str::from_slice(self) } diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs index 27b5979f57394..d764f188be2d6 100644 --- a/src/libcore/tuple.rs +++ b/src/libcore/tuple.rs @@ -55,12 +55,14 @@ impl (&[A], &[B]): ExtendedTupleOps { impl (~[A], ~[B]): ExtendedTupleOps { fn zip() -> ~[(A, B)] { - let (a, b) = self; + // XXX: Bad copy + let (a, b) = copy self; vec::zip(a, b) } fn map(f: fn(A, B) -> C) -> ~[C] { - let (a, b) = self; + // XXX: Bad copy + let (a, b) = copy self; vec::map2(a, b, f) } } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 3f5051ac55bab..0f99ec2a227e1 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -419,7 +419,7 @@ fn rsplit(v: &[T], f: fn(T) -> bool) -> ~[~[T]] { if (ln == 0u) { return ~[] } let mut end = ln; - let mut result = ~[]; + let mut result = ~[mut ]; while end > 0u { match rposition_between(v, 0u, end, f) { None => break, @@ -430,7 +430,8 @@ fn rsplit(v: &[T], f: fn(T) -> bool) -> ~[~[T]] { } } push(result, slice(v, 0u, end)); - reversed(result) + reverse(result); + return from_mut(move result); } /** @@ -443,7 +444,7 @@ fn rsplitn(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] { let mut end = ln; let mut count = n; - let mut result = ~[]; + let mut result = ~[mut ]; while end > 0u && count > 0u { match rposition_between(v, 0u, end, f) { None => break, @@ -456,7 +457,8 @@ fn rsplitn(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] { } } push(result, slice(v, 0u, end)); - reversed(result) + reverse(result); + return from_mut(result); } // Mutators @@ -1481,7 +1483,7 @@ impl @[T]: Ord { impl ~[T]: add<&[const T],~[T]> { #[inline(always)] pure fn add(rhs: &[const T]) -> ~[T] { - append(self, rhs) + append(copy self, rhs) } }