core: deny(vecs_implicity_copyable)

This commit is contained in:
Brian Anderson 2012-09-02 15:37:15 -07:00
parent 7fb1a4e2d1
commit 087c5032a8
12 changed files with 37 additions and 27 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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<T> {
fn parse_buf(buf: &[u8], radix: uint) -> Option<T> {
if vec::len(buf) == 0u { return None; }
let mut i = vec::len(buf) - 1u;
let mut start = 0u;

View File

@ -633,6 +633,7 @@ impl<T: Writer> T : WriterUtil {
fn write_u8(n: u8) { self.write(&[n]) }
}
#[allow(non_implicitly_copyable_typarams)]
fn file_writer(path: &Path, flags: ~[FileFlag]) -> Result<Writer, ~str> {
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())

View File

@ -121,7 +121,7 @@ pure fn foldl<A,B,IA:BaseIter<A>>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B {
}
pure fn to_vec<A:copy,IA:BaseIter<A>>(self: IA) -> ~[A] {
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(r, ~[a]))
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(copy r, ~[a]))
}
pure fn contains<A:Eq,IA:BaseIter<A>>(self: IA, x: A) -> bool {

View File

@ -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)]

View File

@ -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 }

View File

@ -87,7 +87,7 @@ fn with_argv<T>(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<T>(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 \

View File

@ -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)
}
}

View File

@ -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) }

View File

@ -55,12 +55,14 @@ impl<A: copy, B: copy> (&[A], &[B]): ExtendedTupleOps<A,B> {
impl<A: copy, B: copy> (~[A], ~[B]): ExtendedTupleOps<A,B> {
fn zip() -> ~[(A, B)] {
let (a, b) = self;
// XXX: Bad copy
let (a, b) = copy self;
vec::zip(a, b)
}
fn map<C>(f: fn(A, B) -> C) -> ~[C] {
let (a, b) = self;
// XXX: Bad copy
let (a, b) = copy self;
vec::map2(a, b, f)
}
}

View File

@ -419,7 +419,7 @@ fn rsplit<T: copy>(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<T: copy>(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<T: copy>(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<T: copy>(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> @[T]: Ord {
impl<T: copy> ~[T]: add<&[const T],~[T]> {
#[inline(always)]
pure fn add(rhs: &[const T]) -> ~[T] {
append(self, rhs)
append(copy self, rhs)
}
}