Skip to content

Commit b18a151

Browse files
committed
Make with_bytes_reader/with_bytes_writer pure
1 parent 4e03ffd commit b18a151

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/libcore/dvec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub enum DVec<A> {
5656
}
5757

5858
/// Creates a new, empty dvec
59-
pub fn DVec<A>() -> DVec<A> {
59+
pub pure fn DVec<A>() -> DVec<A> {
6060
DVec_({mut data: ~[]})
6161
}
6262

src/libcore/io.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl ByteBuf: Reader {
328328
fn tell() -> uint { self.pos }
329329
}
330330

331-
pub fn with_bytes_reader<t>(bytes: &[u8], f: fn(Reader) -> t) -> t {
331+
pub pure fn with_bytes_reader<t>(bytes: &[u8], f: fn(Reader) -> t) -> t {
332332
f({buf: bytes, mut pos: 0u} as Reader)
333333
}
334334

@@ -730,21 +730,25 @@ impl @BytesWriter : Writer {
730730
fn get_type() -> WriterType { (*self).get_type() }
731731
}
732732

733-
pub fn BytesWriter() -> BytesWriter {
733+
pub pure fn BytesWriter() -> BytesWriter {
734734
BytesWriter { buf: DVec(), mut pos: 0u }
735735
}
736736

737-
pub fn with_bytes_writer(f: fn(Writer)) -> ~[u8] {
737+
pub pure fn with_bytes_writer(f: fn(Writer)) -> ~[u8] {
738738
let wr = @BytesWriter();
739739
f(wr as Writer);
740-
wr.buf.check_out(|buf| move buf)
740+
// FIXME (#3758): This should not be needed.
741+
unsafe { wr.buf.check_out(|buf| move buf) }
741742
}
742743

743-
pub fn with_str_writer(f: fn(Writer)) -> ~str {
744+
pub pure fn with_str_writer(f: fn(Writer)) -> ~str {
744745
let mut v = with_bytes_writer(f);
745746

746-
// Make sure the vector has a trailing null and is proper utf8.
747-
v.push(0);
747+
// FIXME (#3758): This should not be needed.
748+
unsafe {
749+
// Make sure the vector has a trailing null and is proper utf8.
750+
v.push(0);
751+
}
748752
assert str::is_utf8(v);
749753

750754
unsafe { move ::cast::transmute(move v) }

0 commit comments

Comments
 (0)