Skip to content

Commit e844e1d

Browse files
committed
change vec::view sig to be sound (good catch @bblum)
1 parent 2340ef9 commit e844e1d

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/libcore/io.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,10 @@ impl BytesWriter: Writer {
697697
vec::reserve(&mut buf, count);
698698
unsafe { vec::raw::set_len(buf, count); }
699699
700-
let view = vec::mut_view(buf, self.pos, count);
701-
vec::bytes::memcpy(view, v, v_len);
700+
{
701+
let view = vec::mut_view(buf, self.pos, count);
702+
vec::bytes::memcpy(view, v, v_len);
703+
}
702704
703705
self.pos += v_len;
704706

src/libcore/vec.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ pure fn slice<T: Copy>(v: &[const T], start: uint, end: uint) -> ~[T] {
338338
}
339339

340340
/// Return a slice that points into another slice.
341-
pure fn view<T>(v: &[T], start: uint, end: uint) -> &[T] {
341+
pure fn view<T>(v: &r/[T], start: uint, end: uint) -> &r/[T] {
342342
assert (start <= end);
343343
assert (end <= len(v));
344344
do as_imm_buf(v) |p, _len| {
@@ -351,7 +351,7 @@ pure fn view<T>(v: &[T], start: uint, end: uint) -> &[T] {
351351
}
352352

353353
/// Return a slice that points into another slice.
354-
pure fn mut_view<T>(v: &[mut T], start: uint, end: uint) -> &[mut T] {
354+
pure fn mut_view<T>(v: &r/[mut T], start: uint, end: uint) -> &r/[mut T] {
355355
assert (start <= end);
356356
assert (end <= len(v));
357357
do as_mut_buf(v) |p, _len| {
@@ -364,7 +364,8 @@ pure fn mut_view<T>(v: &[mut T], start: uint, end: uint) -> &[mut T] {
364364
}
365365

366366
/// Return a slice that points into another slice.
367-
pure fn const_view<T>(v: &[const T], start: uint, end: uint) -> &[const T] {
367+
pure fn const_view<T>(v: &r/[const T], start: uint,
368+
end: uint) -> &r/[const T] {
368369
assert (start <= end);
369370
assert (end <= len(v));
370371
do as_const_buf(v) |p, _len| {
@@ -1526,7 +1527,7 @@ impl<T: Copy> &[const T]: CopyableVector<T> {
15261527
}
15271528

15281529
trait ImmutableVector<T> {
1529-
pure fn view(start: uint, end: uint) -> &[T];
1530+
pure fn view(start: uint, end: uint) -> &self/[T];
15301531
pure fn foldr<U: Copy>(z: U, p: fn(T, U) -> U) -> U;
15311532
pure fn map<U>(f: fn(v: &T) -> U) -> ~[U];
15321533
pure fn mapi<U>(f: fn(uint, v: &T) -> U) -> ~[U];
@@ -1546,7 +1547,7 @@ trait ImmutableEqVector<T: Eq> {
15461547
/// Extension methods for vectors
15471548
impl<T> &[T]: ImmutableVector<T> {
15481549
/// Return a slice that points into another slice.
1549-
pure fn view(start: uint, end: uint) -> &[T] {
1550+
pure fn view(start: uint, end: uint) -> &self/[T] {
15501551
view(self, start, end)
15511552
}
15521553
/// Reduce a vector from right to left

0 commit comments

Comments
 (0)