Skip to content

Commit 087c503

Browse files
committed
core: deny(vecs_implicity_copyable)
1 parent 7fb1a4e commit 087c503

File tree

12 files changed

+37
-27
lines changed

12 files changed

+37
-27
lines changed

src/libcore/core.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// Don't link to core. We are core.
3232
#[no_core];
3333

34-
#[allow(vecs_implicitly_copyable)];
34+
#[deny(vecs_implicitly_copyable)];
3535

3636
export int, i8, i16, i32, i64;
3737
export uint, u8, u16, u32, u64;

src/libcore/extfmt.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ mod ct {
8686
let mut pieces: ~[piece] = ~[];
8787
let lim = str::len(s);
8888
let mut buf = ~"";
89-
fn flush_buf(buf: ~str, &pieces: ~[piece]) -> ~str {
89+
fn flush_buf(+buf: ~str, &pieces: ~[piece]) -> ~str {
9090
if str::len(buf) > 0u {
9191
let piece = piece_string(buf);
9292
vec::push(pieces, piece);
@@ -109,7 +109,7 @@ mod ct {
109109
} else {
110110
buf = flush_buf(buf, pieces);
111111
let rs = parse_conversion(s, i, lim, error);
112-
vec::push(pieces, rs.piece);
112+
vec::push(pieces, copy rs.piece);
113113
i = rs.next;
114114
}
115115
} else { buf += curr; i += size; }
@@ -148,7 +148,7 @@ mod ct {
148148
let ty = parse_type(s, prec.next, lim, error);
149149
return {piece:
150150
piece_conv({param: parm.param,
151-
flags: flags.flags,
151+
flags: copy flags.flags,
152152
width: width.count,
153153
precision: prec.count,
154154
ty: ty.ty}),
@@ -177,12 +177,12 @@ mod ct {
177177
fn more_(f: flag, s: ~str, i: uint, lim: uint) ->
178178
{flags: ~[flag], next: uint} {
179179
let next = parse_flags(s, i + 1u, lim);
180-
let rest = next.flags;
180+
let rest = copy next.flags;
181181
let j = next.next;
182182
let curr: ~[flag] = ~[f];
183183
return {flags: vec::append(curr, rest), next: j};
184184
}
185-
let more = |x| more_(x, s, i, lim);
185+
let more = |x, copy s| more_(x, copy s, i, lim);
186186
let f = s[i];
187187
return if f == '-' as u8 {
188188
more(flag_left_justify)
@@ -404,14 +404,14 @@ mod rt {
404404

405405
fn pad(cv: conv, &s: ~str, mode: pad_mode) -> ~str {
406406
let uwidth : uint = match cv.width {
407-
count_implied => return s,
407+
count_implied => return copy s,
408408
count_is(width) => {
409409
// FIXME: width should probably be uint (see Issue #1996)
410410
width as uint
411411
}
412412
};
413413
let strlen = str::char_len(s);
414-
if uwidth <= strlen { return s; }
414+
if uwidth <= strlen { return copy s; }
415415
let mut padchar = ' ';
416416
let diff = uwidth - strlen;
417417
if have_flag(cv.flags, flag_left_justify) {

src/libcore/int-template.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl T: iter::TimesIx {
137137
* * buf - A byte buffer
138138
* * radix - The base of the number
139139
*/
140-
fn parse_buf(buf: ~[u8], radix: uint) -> Option<T> {
140+
fn parse_buf(buf: &[u8], radix: uint) -> Option<T> {
141141
if vec::len(buf) == 0u { return None; }
142142
let mut i = vec::len(buf) - 1u;
143143
let mut start = 0u;

src/libcore/io.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ impl<T: Writer> T : WriterUtil {
633633
fn write_u8(n: u8) { self.write(&[n]) }
634634
}
635635

636+
#[allow(non_implicitly_copyable_typarams)]
636637
fn file_writer(path: &Path, flags: ~[FileFlag]) -> Result<Writer, ~str> {
637638
result::chain(mk_file_writer(path, flags), |w| result::Ok(w))
638639
}
@@ -726,6 +727,7 @@ fn seek_in_buf(offset: int, pos: uint, len: uint, whence: SeekStyle) ->
726727
return bpos as uint;
727728
}
728729
730+
#[allow(non_implicitly_copyable_typarams)]
729731
fn read_whole_file_str(file: &Path) -> Result<~str, ~str> {
730732
result::chain(read_whole_file(file), |bytes| {
731733
if str::is_utf8(bytes) {
@@ -738,6 +740,7 @@ fn read_whole_file_str(file: &Path) -> Result<~str, ~str> {
738740

739741
// FIXME (#2004): implement this in a low-level way. Going through the
740742
// abstractions is pointless.
743+
#[allow(non_implicitly_copyable_typarams)]
741744
fn read_whole_file(file: &Path) -> Result<~[u8], ~str> {
742745
result::chain(file_reader(file), |rdr| {
743746
result::Ok(rdr.read_whole_stream())

src/libcore/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pure fn foldl<A,B,IA:BaseIter<A>>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B {
121121
}
122122

123123
pure fn to_vec<A:copy,IA:BaseIter<A>>(self: IA) -> ~[A] {
124-
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(r, ~[a]))
124+
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(copy r, ~[a]))
125125
}
126126

127127
pure fn contains<A:Eq,IA:BaseIter<A>>(self: IA, x: A) -> bool {

src/libcore/os.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ mod global_env {
213213
for vec::each(rustrt::rust_env_pairs()) |p| {
214214
let vs = str::splitn_char(p, '=', 1u);
215215
assert vec::len(vs) == 2u;
216-
vec::push(pairs, (vs[0], vs[1]));
216+
vec::push(pairs, (copy vs[0], copy vs[1]));
217217
}
218218
return pairs;
219219
}
@@ -504,12 +504,14 @@ fn tmpdir() -> Path {
504504
}
505505

506506
#[cfg(unix)]
507+
#[allow(non_implicitly_copyable_typarams)]
507508
fn lookup() -> Path {
508509
option::get_default(getenv_nonempty("TMPDIR"),
509510
Path("/tmp"))
510511
}
511512

512513
#[cfg(windows)]
514+
#[allow(non_implicitly_copyable_typarams)]
513515
fn lookup() -> Path {
514516
option::get_default(
515517
option::or(getenv_nonempty("TMP"),
@@ -609,6 +611,7 @@ fn make_dir(p: &Path, mode: c_int) -> bool {
609611
}
610612

611613
/// Lists the contents of a directory
614+
#[allow(non_implicitly_copyable_typarams)]
612615
fn list_dir(p: &Path) -> ~[~str] {
613616

614617
#[cfg(unix)]

src/libcore/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl PosixPath : GenericPath {
200200
}
201201

202202
pure fn push(s: &str) -> PosixPath {
203-
let mut cs = self.components;
203+
let mut cs = copy self.components;
204204
unchecked { vec::push(cs, move str::from_slice(s)); }
205205
return PosixPath { components: move cs,
206206
..self }
@@ -389,7 +389,7 @@ impl WindowsPath : GenericPath {
389389
}
390390

391391
pure fn push(s: &str) -> WindowsPath {
392-
let mut cs = self.components;
392+
let mut cs = copy self.components;
393393
unchecked { vec::push(cs, move str::from_slice(s)); }
394394
return WindowsPath { components: move cs,
395395
..self }

src/libcore/run.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn with_argv<T>(prog: &str, args: &[~str],
8787
let mut argptrs = str::as_c_str(prog, |b| ~[b]);
8888
let mut tmps = ~[];
8989
for vec::each(args) |arg| {
90-
let t = @arg;
90+
let t = @copy arg;
9191
vec::push(tmps, t);
9292
vec::push_all(argptrs, str::as_c_str(*t, |b| ~[b]));
9393
}
@@ -106,7 +106,7 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
106106
let mut ptrs = ~[];
107107

108108
for vec::each(es) |e| {
109-
let (k,v) = e;
109+
let (k,v) = copy e;
110110
let t = @(fmt!("%s=%s", k, v));
111111
vec::push(tmps, t);
112112
vec::push_all(ptrs, str::as_c_str(*t, |b| ~[b]));
@@ -315,10 +315,10 @@ fn program_output(prog: &str, args: &[~str]) ->
315315
let stream = comm::recv(p);
316316
match stream {
317317
(1, s) => {
318-
outs = s;
318+
outs = copy s;
319319
}
320320
(2, s) => {
321-
errs = s;
321+
errs = copy s;
322322
}
323323
(n, _) => {
324324
fail(fmt!("program_output received an unexpected file \

src/libcore/str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ pure fn lines(s: &str) -> ~[~str] { split_char(s, '\n') }
605605
pure fn lines_any(s: &str) -> ~[~str] {
606606
vec::map(lines(s), |s| {
607607
let l = len(s);
608-
let mut cp = s;
608+
let mut cp = copy s;
609609
if l > 0u && s[l - 1u] == '\r' as u8 {
610610
unsafe { unsafe::set_len(cp, l - 1u); }
611611
}
@@ -2068,7 +2068,7 @@ impl ~str: UniqueStr {
20682068
impl ~str: add<&str,~str> {
20692069
#[inline(always)]
20702070
pure fn add(rhs: &str) -> ~str {
2071-
append(self, rhs)
2071+
append(copy self, rhs)
20722072
}
20732073
}
20742074

src/libcore/to_str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl (): ToStr {
4444
fn to_str() -> ~str { ~"()" }
4545
}
4646
impl ~str: ToStr {
47-
fn to_str() -> ~str { self }
47+
fn to_str() -> ~str { copy self }
4848
}
4949
impl &str: ToStr {
5050
fn to_str() -> ~str { str::from_slice(self) }

src/libcore/tuple.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ impl<A: copy, B: copy> (&[A], &[B]): ExtendedTupleOps<A,B> {
5555
impl<A: copy, B: copy> (~[A], ~[B]): ExtendedTupleOps<A,B> {
5656

5757
fn zip() -> ~[(A, B)] {
58-
let (a, b) = self;
58+
// XXX: Bad copy
59+
let (a, b) = copy self;
5960
vec::zip(a, b)
6061
}
6162

6263
fn map<C>(f: fn(A, B) -> C) -> ~[C] {
63-
let (a, b) = self;
64+
// XXX: Bad copy
65+
let (a, b) = copy self;
6466
vec::map2(a, b, f)
6567
}
6668
}

src/libcore/vec.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ fn rsplit<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
419419
if (ln == 0u) { return ~[] }
420420

421421
let mut end = ln;
422-
let mut result = ~[];
422+
let mut result = ~[mut ];
423423
while end > 0u {
424424
match rposition_between(v, 0u, end, f) {
425425
None => break,
@@ -430,7 +430,8 @@ fn rsplit<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
430430
}
431431
}
432432
push(result, slice(v, 0u, end));
433-
reversed(result)
433+
reverse(result);
434+
return from_mut(move result);
434435
}
435436

436437
/**
@@ -443,7 +444,7 @@ fn rsplitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
443444

444445
let mut end = ln;
445446
let mut count = n;
446-
let mut result = ~[];
447+
let mut result = ~[mut ];
447448
while end > 0u && count > 0u {
448449
match rposition_between(v, 0u, end, f) {
449450
None => break,
@@ -456,7 +457,8 @@ fn rsplitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
456457
}
457458
}
458459
push(result, slice(v, 0u, end));
459-
reversed(result)
460+
reverse(result);
461+
return from_mut(result);
460462
}
461463

462464
// Mutators
@@ -1481,7 +1483,7 @@ impl<T: Ord> @[T]: Ord {
14811483
impl<T: copy> ~[T]: add<&[const T],~[T]> {
14821484
#[inline(always)]
14831485
pure fn add(rhs: &[const T]) -> ~[T] {
1484-
append(self, rhs)
1486+
append(copy self, rhs)
14851487
}
14861488
}
14871489

0 commit comments

Comments
 (0)