From 40b9f5ded50ac4ce8c9323921ec556ad611af6b7 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Wed, 24 Sep 2014 23:41:09 +1200 Subject: Use slice syntax instead of slice_to, etc. --- src/libstd/io/buffered.rs | 14 +++++++------- src/libstd/io/comm_adapters.rs | 9 ++++----- src/libstd/io/fs.rs | 8 ++++---- src/libstd/io/mem.rs | 22 +++++++++++----------- src/libstd/io/mod.rs | 14 +++++++------- src/libstd/io/net/ip.rs | 6 +++--- src/libstd/io/net/udp.rs | 2 +- src/libstd/io/util.rs | 8 ++++---- src/libstd/num/i16.rs | 1 - src/libstd/num/i32.rs | 1 - src/libstd/num/i64.rs | 1 - src/libstd/num/i8.rs | 1 - src/libstd/num/int.rs | 1 - src/libstd/num/int_macros.rs | 2 +- src/libstd/num/strconv.rs | 2 +- src/libstd/num/u16.rs | 1 - src/libstd/num/u32.rs | 1 - src/libstd/num/u64.rs | 1 - src/libstd/num/u8.rs | 1 - src/libstd/num/uint.rs | 1 - src/libstd/num/uint_macros.rs | 2 +- src/libstd/path/mod.rs | 8 ++++---- src/libstd/path/posix.rs | 20 ++++++++++---------- 23 files changed, 58 insertions(+), 69 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index d9543a06b35..754b440b0de 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -90,10 +90,10 @@ impl BufferedReader { impl Buffer for BufferedReader { fn fill_buf<'a>(&'a mut self) -> IoResult<&'a [u8]> { if self.pos == self.cap { - self.cap = try!(self.inner.read(self.buf.as_mut_slice())); + self.cap = try!(self.inner.read(self.buf[mut])); self.pos = 0; } - Ok(self.buf.slice(self.pos, self.cap)) + Ok(self.buf[self.pos..self.cap]) } fn consume(&mut self, amt: uint) { @@ -107,7 +107,7 @@ impl Reader for BufferedReader { let nread = { let available = try!(self.fill_buf()); let nread = cmp::min(available.len(), buf.len()); - slice::bytes::copy_memory(buf, available.slice_to(nread)); + slice::bytes::copy_memory(buf, available[..nread]); nread }; self.pos += nread; @@ -162,7 +162,7 @@ impl BufferedWriter { fn flush_buf(&mut self) -> IoResult<()> { if self.pos != 0 { - let ret = self.inner.as_mut().unwrap().write(self.buf.slice_to(self.pos)); + let ret = self.inner.as_mut().unwrap().write(self.buf[..self.pos]); self.pos = 0; ret } else { @@ -195,7 +195,7 @@ impl Writer for BufferedWriter { if buf.len() > self.buf.len() { self.inner.as_mut().unwrap().write(buf) } else { - let dst = self.buf.slice_from_mut(self.pos); + let dst = self.buf[mut self.pos..]; slice::bytes::copy_memory(dst, buf); self.pos += buf.len(); Ok(()) @@ -250,9 +250,9 @@ impl Writer for LineBufferedWriter { fn write(&mut self, buf: &[u8]) -> IoResult<()> { match buf.iter().rposition(|&b| b == b'\n') { Some(i) => { - try!(self.inner.write(buf.slice_to(i + 1))); + try!(self.inner.write(buf[..i + 1])); try!(self.inner.flush()); - try!(self.inner.write(buf.slice_from(i + 1))); + try!(self.inner.write(buf[i + 1..])); Ok(()) } None => self.inner.write(buf), diff --git a/src/libstd/io/comm_adapters.rs b/src/libstd/io/comm_adapters.rs index 0a969fc37c9..5bec131f222 100644 --- a/src/libstd/io/comm_adapters.rs +++ b/src/libstd/io/comm_adapters.rs @@ -15,8 +15,7 @@ use comm::{Sender, Receiver}; use io; use option::{None, Option, Some}; use result::{Ok, Err}; -use slice::{bytes, MutableSlice, ImmutableSlice, CloneableVector}; -use str::StrSlice; +use slice::{bytes, CloneableVector}; use super::{Reader, Writer, IoResult}; use vec::Vec; @@ -62,10 +61,10 @@ impl Reader for ChanReader { loop { match self.buf { Some(ref prev) => { - let dst = buf.slice_from_mut(num_read); - let src = prev.slice_from(self.pos); + let dst = buf[mut num_read..]; + let src = prev[self.pos..]; let count = cmp::min(dst.len(), src.len()); - bytes::copy_memory(dst, src.slice_to(count)); + bytes::copy_memory(dst, src[..count]); num_read += count; self.pos += count; }, diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index f777460e66a..66d20835fb2 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -485,7 +485,7 @@ pub fn copy(from: &Path, to: &Path) -> IoResult<()> { Err(ref e) if e.kind == io::EndOfFile => { break } Err(e) => return update_err(Err(e), from, to) }; - try!(writer.write(buf.slice_to(amt))); + try!(writer.write(buf[..amt])); } chmod(to, try!(update_err(from.stat(), from, to)).perm) @@ -1014,7 +1014,7 @@ mod test { let mut read_buf = [0, .. 1028]; let read_str = match check!(read_stream.read(read_buf)) { -1|0 => fail!("shouldn't happen"), - n => str::from_utf8(read_buf.slice_to(n)).unwrap().to_string() + n => str::from_utf8(read_buf[..n]).unwrap().to_string() }; assert_eq!(read_str.as_slice(), message); } @@ -1061,11 +1061,11 @@ mod test { { let mut read_stream = File::open_mode(filename, Open, Read); { - let read_buf = read_mem.slice_mut(0, 4); + let read_buf = read_mem[mut 0..4]; check!(read_stream.read(read_buf)); } { - let read_buf = read_mem.slice_mut(4, 8); + let read_buf = read_mem[mut 4..8]; check!(read_stream.read(read_buf)); } } diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index c826bd16715..ca9692ee158 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -19,7 +19,7 @@ use result::{Err, Ok}; use io; use io::{Reader, Writer, Seek, Buffer, IoError, SeekStyle, IoResult}; use slice; -use slice::{Slice, ImmutableSlice, MutableSlice}; +use slice::Slice; use vec::Vec; static BUF_CAPACITY: uint = 128; @@ -146,8 +146,8 @@ impl Reader for MemReader { let write_len = min(buf.len(), self.buf.len() - self.pos); { - let input = self.buf.slice(self.pos, self.pos + write_len); - let output = buf.slice_mut(0, write_len); + let input = self.buf[self.pos.. self.pos + write_len]; + let output = buf[mut ..write_len]; assert_eq!(input.len(), output.len()); slice::bytes::copy_memory(output, input); } @@ -174,7 +174,7 @@ impl Buffer for MemReader { #[inline] fn fill_buf<'a>(&'a mut self) -> IoResult<&'a [u8]> { if self.pos < self.buf.len() { - Ok(self.buf.slice_from(self.pos)) + Ok(self.buf[self.pos..]) } else { Err(io::standard_error(io::EndOfFile)) } @@ -232,7 +232,7 @@ impl<'a> Writer for BufWriter<'a> { }) } - slice::bytes::copy_memory(self.buf.slice_from_mut(self.pos), buf); + slice::bytes::copy_memory(self.buf[mut self.pos..], buf); self.pos += buf.len(); Ok(()) } @@ -292,8 +292,8 @@ impl<'a> Reader for BufReader<'a> { let write_len = min(buf.len(), self.buf.len() - self.pos); { - let input = self.buf.slice(self.pos, self.pos + write_len); - let output = buf.slice_mut(0, write_len); + let input = self.buf[self.pos.. self.pos + write_len]; + let output = buf[mut ..write_len]; assert_eq!(input.len(), output.len()); slice::bytes::copy_memory(output, input); } @@ -320,7 +320,7 @@ impl<'a> Buffer for BufReader<'a> { #[inline] fn fill_buf<'a>(&'a mut self) -> IoResult<&'a [u8]> { if self.pos < self.buf.len() { - Ok(self.buf.slice_from(self.pos)) + Ok(self.buf[self.pos..]) } else { Err(io::standard_error(io::EndOfFile)) } @@ -427,7 +427,7 @@ mod test { assert_eq!(buf.as_slice(), b); assert_eq!(reader.read(buf), Ok(3)); let b: &[_] = &[5, 6, 7]; - assert_eq!(buf.slice(0, 3), b); + assert_eq!(buf[0..3], b); assert!(reader.read(buf).is_err()); let mut reader = MemReader::new(vec!(0, 1, 2, 3, 4, 5, 6, 7)); assert_eq!(reader.read_until(3).unwrap(), vec!(0, 1, 2, 3)); @@ -454,7 +454,7 @@ mod test { assert_eq!(buf.as_slice(), b); assert_eq!(reader.read(buf), Ok(3)); let b: &[_] = &[5, 6, 7]; - assert_eq!(buf.slice(0, 3), b); + assert_eq!(buf[0..3], b); assert!(reader.read(buf).is_err()); let mut reader = BufReader::new(in_buf.as_slice()); assert_eq!(reader.read_until(3).unwrap(), vec!(0, 1, 2, 3)); @@ -548,7 +548,7 @@ mod test { assert!(r.read_at_least(buf.len(), buf).is_ok()); let b: &[_] = &[1, 2, 3]; assert_eq!(buf.as_slice(), b); - assert!(r.read_at_least(0, buf.slice_to_mut(0)).is_ok()); + assert!(r.read_at_least(0, buf[mut ..0]).is_ok()); assert_eq!(buf.as_slice(), b); assert!(r.read_at_least(buf.len(), buf).is_ok()); let b: &[_] = &[4, 5, 6]; diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index b929e7c464d..9768539b23e 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -235,7 +235,7 @@ use os; use boxed::Box; use result::{Ok, Err, Result}; use rt::rtio; -use slice::{Slice, MutableSlice, ImmutableSlice}; +use slice::{Slice, ImmutableSlice}; use str::{Str, StrSlice}; use str; use string::String; @@ -575,7 +575,7 @@ pub trait Reader { while read < min { let mut zeroes = 0; loop { - match self.read(buf.slice_from_mut(read)) { + match self.read(buf[mut read..]) { Ok(0) => { zeroes += 1; if zeroes >= NO_PROGRESS_LIMIT { @@ -1111,8 +1111,8 @@ pub trait Writer { #[inline] fn write_char(&mut self, c: char) -> IoResult<()> { let mut buf = [0u8, ..4]; - let n = c.encode_utf8(buf.as_mut_slice()).unwrap_or(0); - self.write(buf.slice_to(n)) + let n = c.encode_utf8(buf[mut]).unwrap_or(0); + self.write(buf[..n]) } /// Write the result of passing n through `int::to_str_bytes`. @@ -1496,7 +1496,7 @@ pub trait Buffer: Reader { }; match available.iter().position(|&b| b == byte) { Some(i) => { - res.push_all(available.slice_to(i + 1)); + res.push_all(available[..i + 1]); used = i + 1; break } @@ -1528,14 +1528,14 @@ pub trait Buffer: Reader { { let mut start = 1; while start < width { - match try!(self.read(buf.slice_mut(start, width))) { + match try!(self.read(buf[mut start..width])) { n if n == width - start => break, n if n < width - start => { start += n; } _ => return Err(standard_error(InvalidInput)), } } } - match str::from_utf8(buf.slice_to(width)) { + match str::from_utf8(buf[..width]) { Some(s) => Ok(s.char_at(0)), None => Err(standard_error(InvalidInput)) } diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index 6eb7d1c02fb..5140159e4ea 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -21,7 +21,7 @@ use from_str::FromStr; use iter::Iterator; use option::{Option, None, Some}; use str::StrSlice; -use slice::{MutableCloneableSlice, ImmutableSlice, MutableSlice}; +use slice::{MutableCloneableSlice, MutableSlice}; pub type Port = u16; @@ -241,7 +241,7 @@ impl<'a> Parser<'a> { assert!(head.len() + tail.len() <= 8); let mut gs = [0u16, ..8]; gs.clone_from_slice(head); - gs.slice_mut(8 - tail.len(), 8).clone_from_slice(tail); + gs[mut 8 - tail.len() .. 8].clone_from_slice(tail); Ipv6Addr(gs[0], gs[1], gs[2], gs[3], gs[4], gs[5], gs[6], gs[7]) } @@ -303,7 +303,7 @@ impl<'a> Parser<'a> { let mut tail = [0u16, ..8]; let (tail_size, _) = read_groups(self, &mut tail, 8 - head_size); - Some(ipv6_addr_from_head_tail(head.slice(0, head_size), tail.slice(0, tail_size))) + Some(ipv6_addr_from_head_tail(head[..head_size], tail[..tail_size])) } fn read_ipv6_addr(&mut self) -> Option { diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index 3ba8765fc3e..4dd6f448ee5 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -48,7 +48,7 @@ use rt::rtio; /// match socket.recv_from(buf) { /// Ok((amt, src)) => { /// // Send a reply to the socket we received data from -/// let buf = buf.slice_to_mut(amt); +/// let buf = buf[mut ..amt]; /// buf.reverse(); /// socket.send_to(buf, src); /// } diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 16ac8c4c265..820ae931f32 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -47,7 +47,7 @@ impl Reader for LimitReader { } let len = cmp::min(self.limit, buf.len()); - let res = self.inner.read(buf.slice_to_mut(len)); + let res = self.inner.read(buf[mut ..len]); match res { Ok(len) => self.limit -= len, _ => {} @@ -59,7 +59,7 @@ impl Reader for LimitReader { impl Buffer for LimitReader { fn fill_buf<'a>(&'a mut self) -> io::IoResult<&'a [u8]> { let amt = try!(self.inner.fill_buf()); - let buf = amt.slice_to(cmp::min(amt.len(), self.limit)); + let buf = amt[..cmp::min(amt.len(), self.limit)]; if buf.len() == 0 { Err(io::standard_error(io::EndOfFile)) } else { @@ -216,7 +216,7 @@ impl TeeReader { impl Reader for TeeReader { fn read(&mut self, buf: &mut [u8]) -> io::IoResult { self.reader.read(buf).and_then(|len| { - self.writer.write(buf.slice_to(len)).map(|()| len) + self.writer.write(buf[mut ..len]).map(|()| len) }) } } @@ -230,7 +230,7 @@ pub fn copy(r: &mut R, w: &mut W) -> io::IoResult<()> { Err(ref e) if e.kind == io::EndOfFile => return Ok(()), Err(e) => return Err(e), }; - try!(w.write(buf.slice_to(len))); + try!(w.write(buf[..len])); } } diff --git a/src/libstd/num/i16.rs b/src/libstd/num/i16.rs index f5b2f31a127..9e4cc06f0a2 100644 --- a/src/libstd/num/i16.rs +++ b/src/libstd/num/i16.rs @@ -17,7 +17,6 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableSlice; use string::String; pub use core::i16::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/i32.rs b/src/libstd/num/i32.rs index 623a10725c8..54259fcad55 100644 --- a/src/libstd/num/i32.rs +++ b/src/libstd/num/i32.rs @@ -17,7 +17,6 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableSlice; use string::String; pub use core::i32::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/i64.rs b/src/libstd/num/i64.rs index ffb1307908c..b5fe6825ca4 100644 --- a/src/libstd/num/i64.rs +++ b/src/libstd/num/i64.rs @@ -17,7 +17,6 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableSlice; use string::String; pub use core::i64::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/i8.rs b/src/libstd/num/i8.rs index 4fbb7381238..7aa9a41e340 100644 --- a/src/libstd/num/i8.rs +++ b/src/libstd/num/i8.rs @@ -17,7 +17,6 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableSlice; use string::String; pub use core::i8::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/int.rs b/src/libstd/num/int.rs index 7821306f5fc..74ee61634c6 100644 --- a/src/libstd/num/int.rs +++ b/src/libstd/num/int.rs @@ -17,7 +17,6 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableSlice; use string::String; pub use core::int::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs index 3c01edf2339..62e609bb2e1 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libstd/num/int_macros.rs @@ -78,7 +78,7 @@ pub fn to_str_bytes(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U { (write!(&mut wr, "{}", ::fmt::radix(n, radix as u8))).unwrap(); wr.tell().unwrap() as uint }; - f(buf.slice(0, amt)) + f(buf[..amt]) } #[deprecated = "use fmt::radix"] diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index b15f334e233..f97bbe0dc8e 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -730,7 +730,7 @@ pub fn from_str_bytes_common+ // parse remaining bytes as decimal integer, // skipping the exponent char let exp: Option = from_str_bytes_common( - buf.slice(i+1, len), 10, true, false, false, ExpNone, false, + buf[i+1..len], 10, true, false, false, ExpNone, false, ignore_underscores); match exp { diff --git a/src/libstd/num/u16.rs b/src/libstd/num/u16.rs index 0f00f99e980..c141ecc9cba 100644 --- a/src/libstd/num/u16.rs +++ b/src/libstd/num/u16.rs @@ -17,7 +17,6 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableSlice; use string::String; pub use core::u16::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/u32.rs b/src/libstd/num/u32.rs index e6c6bc377b7..8a8e2729a53 100644 --- a/src/libstd/num/u32.rs +++ b/src/libstd/num/u32.rs @@ -17,7 +17,6 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableSlice; use string::String; pub use core::u32::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/u64.rs b/src/libstd/num/u64.rs index 7eb9e1a082f..1b4f8bc433f 100644 --- a/src/libstd/num/u64.rs +++ b/src/libstd/num/u64.rs @@ -17,7 +17,6 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableSlice; use string::String; pub use core::u64::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/u8.rs b/src/libstd/num/u8.rs index 300dd3bcc01..28f22429235 100644 --- a/src/libstd/num/u8.rs +++ b/src/libstd/num/u8.rs @@ -17,7 +17,6 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableSlice; use string::String; pub use core::u8::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/uint.rs b/src/libstd/num/uint.rs index 0adc22e3214..da328074453 100644 --- a/src/libstd/num/uint.rs +++ b/src/libstd/num/uint.rs @@ -17,7 +17,6 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableSlice; use string::String; pub use core::uint::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index cfcaf0fa8da..a033308af16 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -79,7 +79,7 @@ pub fn to_str_bytes(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U { (write!(&mut wr, "{}", ::fmt::radix(n, radix as u8))).unwrap(); wr.tell().unwrap() as uint }; - f(buf.slice(0, amt)) + f(buf[..amt]) } #[deprecated = "use fmt::radix"] diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 16552daae36..63c81695aff 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -357,7 +357,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { match name.rposition_elem(&dot) { None | Some(0) => name, Some(1) if name == b".." => name, - Some(pos) => name.slice_to(pos) + Some(pos) => name[..pos] } }) } @@ -404,7 +404,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { match name.rposition_elem(&dot) { None | Some(0) => None, Some(1) if name == b".." => None, - Some(pos) => Some(name.slice_from(pos+1)) + Some(pos) => Some(name[pos+1..]) } } } @@ -480,7 +480,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { let extlen = extension.container_as_bytes().len(); match (name.rposition_elem(&dot), extlen) { (None, 0) | (Some(0), 0) => None, - (Some(idx), 0) => Some(name.slice_to(idx).to_vec()), + (Some(idx), 0) => Some(name[..idx].to_vec()), (idx, extlen) => { let idx = match idx { None | Some(0) => name.len(), @@ -489,7 +489,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { let mut v; v = Vec::with_capacity(idx + extlen + 1); - v.push_all(name.slice_to(idx)); + v.push_all(name[..idx]); v.push(dot); v.push_all(extension.container_as_bytes()); Some(v) diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 9c4139853c5..3043c25f761 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -165,7 +165,7 @@ impl GenericPathUnsafe for Path { None => { self.repr = Path::normalize(filename); } - Some(idx) if self.repr.slice_from(idx+1) == b".." => { + Some(idx) if self.repr[idx+1..] == b".." => { let mut v = Vec::with_capacity(self.repr.len() + 1 + filename.len()); v.push_all(self.repr.as_slice()); v.push(SEP_BYTE); @@ -175,7 +175,7 @@ impl GenericPathUnsafe for Path { } Some(idx) => { let mut v = Vec::with_capacity(idx + 1 + filename.len()); - v.push_all(self.repr.slice_to(idx+1)); + v.push_all(self.repr[..idx+1]); v.push_all(filename); // FIXME: this is slow self.repr = Path::normalize(v.as_slice()); @@ -216,9 +216,9 @@ impl GenericPath for Path { match self.sepidx { None if b".." == self.repr.as_slice() => self.repr.as_slice(), None => dot_static, - Some(0) => self.repr.slice_to(1), - Some(idx) if self.repr.slice_from(idx+1) == b".." => self.repr.as_slice(), - Some(idx) => self.repr.slice_to(idx) + Some(0) => self.repr[..1], + Some(idx) if self.repr[idx+1..] == b".." => self.repr.as_slice(), + Some(idx) => self.repr[..idx] } } @@ -227,9 +227,9 @@ impl GenericPath for Path { None if b"." == self.repr.as_slice() || b".." == self.repr.as_slice() => None, None => Some(self.repr.as_slice()), - Some(idx) if self.repr.slice_from(idx+1) == b".." => None, - Some(0) if self.repr.slice_from(1).is_empty() => None, - Some(idx) => Some(self.repr.slice_from(idx+1)) + Some(idx) if self.repr[idx+1..] == b".." => None, + Some(0) if self.repr[1..].is_empty() => None, + Some(idx) => Some(self.repr[idx+1..]) } } @@ -371,7 +371,7 @@ impl Path { // borrowck is being very picky let val = { let is_abs = !v.as_slice().is_empty() && v.as_slice()[0] == SEP_BYTE; - let v_ = if is_abs { v.as_slice().slice_from(1) } else { v.as_slice() }; + let v_ = if is_abs { v.as_slice()[1..] } else { v.as_slice() }; let comps = normalize_helper(v_, is_abs); match comps { None => None, @@ -410,7 +410,7 @@ impl Path { /// A path of "/" yields no components. A path of "." yields one component. pub fn components<'a>(&'a self) -> Components<'a> { let v = if self.repr[0] == SEP_BYTE { - self.repr.slice_from(1) + self.repr[1..] } else { self.repr.as_slice() }; let mut ret = v.split(is_sep_byte); if v.is_empty() { -- cgit 1.4.1-3-g733a5 From 95cfc35607ccf5f02f02de56a35a9ef50fa23a82 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Fri, 26 Sep 2014 17:48:16 +1200 Subject: Put slicing syntax behind a feature gate. [breaking-change] If you are using slicing syntax you will need to add #![feature(slicing_syntax)] to your crate. --- src/compiletest/compiletest.rs | 2 +- src/doc/reference.md | 2 +- src/libcollections/lib.rs | 3 ++- src/libcollections/slice.rs | 9 +++++--- src/libcollections/string.rs | 4 ++-- src/libcore/lib.rs | 3 ++- src/libcore/ops.rs | 6 ++--- src/libcore/slice.rs | 4 ++-- src/libcoretest/lib.rs | 2 +- src/libnative/lib.rs | 3 ++- src/libnum/lib.rs | 3 ++- src/librbml/lib.rs | 3 ++- src/libregex/lib.rs | 3 ++- src/librustc/lib.rs | 3 ++- src/librustc_back/lib.rs | 3 ++- src/librustdoc/lib.rs | 3 ++- src/librustrt/lib.rs | 3 ++- src/libserialize/lib.rs | 3 ++- src/libstd/io/net/udp.rs | 33 +++++++++++++++------------ src/libstd/lib.rs | 3 ++- src/libsyntax/feature_gate.rs | 6 +++++ src/libsyntax/lib.rs | 3 ++- src/libterm/lib.rs | 3 ++- src/test/bench/shootout-fannkuch-redux.rs | 2 ++ src/test/bench/shootout-fasta-redux.rs | 2 ++ src/test/bench/shootout-fasta.rs | 2 ++ src/test/bench/shootout-k-nucleotide-pipes.rs | 2 ++ src/test/bench/shootout-k-nucleotide.rs | 2 ++ src/test/bench/shootout-regex-dna.rs | 2 +- src/test/bench/shootout-reverse-complement.rs | 2 ++ src/test/compile-fail/issue-15730.rs | 2 ++ src/test/compile-fail/slice-2.rs | 2 ++ src/test/compile-fail/slice-borrow.rs | 2 ++ src/test/compile-fail/slice-mut-2.rs | 2 ++ src/test/compile-fail/slice-mut.rs | 2 ++ src/test/debuginfo/vec-slices.rs | 1 + src/test/run-pass/issue-3888-2.rs | 2 ++ src/test/run-pass/issue-4464.rs | 2 ++ src/test/run-pass/issue-8898.rs | 1 + src/test/run-pass/slice-2.rs | 2 ++ src/test/run-pass/slice-fail-1.rs | 2 ++ src/test/run-pass/slice-fail-2.rs | 2 ++ src/test/run-pass/slice.rs | 2 ++ 43 files changed, 105 insertions(+), 43 deletions(-) (limited to 'src/libstd') diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 0a486ef0305..1e5e3ebdb34 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -9,7 +9,7 @@ // except according to those terms. #![crate_type = "bin"] -#![feature(phase)] +#![feature(phase, slicing_syntax)] #![deny(warnings)] diff --git a/src/doc/reference.md b/src/doc/reference.md index 3da3d4c5807..c3b61f6435c 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -3828,7 +3828,7 @@ type signature of `print`, and the cast expression in `main`. Within the body of an item that has type parameter declarations, the names of its type parameters are types: -``` +```ignore fn map(f: |A| -> B, xs: &[A]) -> Vec { if xs.len() == 0 { return vec![]; diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 8b9a0ec796e..4d0aaf83907 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -19,8 +19,9 @@ html_root_url = "http://doc.rust-lang.org/master/", html_playground_url = "http://play.rust-lang.org/")] +#![allow(unknown_features)] #![feature(macro_rules, managed_boxes, default_type_params, phase, globs)] -#![feature(unsafe_destructor, import_shadowing)] +#![feature(unsafe_destructor, import_shadowing, slicing_syntax)] #![no_std] #[phase(plugin, link)] extern crate core; diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 9cd01617916..60692ceb401 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -51,9 +51,12 @@ //! interval `[a, b)`: //! //! ```rust -//! let numbers = [0i, 1i, 2i]; -//! let last_numbers = numbers[1..3]; -//! // last_numbers is now &[1i, 2i] +//! #![feature(slicing_syntax)] +//! fn main() { +//! let numbers = [0i, 1i, 2i]; +//! let last_numbers = numbers[1..3]; +//! // last_numbers is now &[1i, 2i] +//! } //! ``` //! //! ## Implementations of other traits diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 31bd377a8de..206e392f664 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -160,7 +160,7 @@ impl String { if i > 0 { unsafe { - res.as_mut_vec().push_all(v.[..i]) + res.as_mut_vec().push_all(v[..i]) }; } @@ -177,7 +177,7 @@ impl String { macro_rules! error(() => ({ unsafe { if subseqidx != i_ { - res.as_mut_vec().push_all(vv[subseqidx..i_]); + res.as_mut_vec().push_all(v[subseqidx..i_]); } subseqidx = i; res.as_mut_vec().push_all(REPLACEMENT); diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 7e2ea492d4c..4890dc2bb73 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -57,8 +57,9 @@ html_playground_url = "http://play.rust-lang.org/")] #![no_std] +#![allow(unknown_features)] #![feature(globs, intrinsics, lang_items, macro_rules, managed_boxes, phase)] -#![feature(simd, unsafe_destructor)] +#![feature(simd, unsafe_destructor, slicing_syntax)] #![deny(missing_doc)] mod macros; diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 77cee2b9863..422c496995b 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -684,7 +684,7 @@ pub trait IndexMut { * A trivial implementation of `Slice`. When `Foo[..Foo]` happens, it ends up * calling `slice_to`, and therefore, `main` prints `Slicing!`. * - * ``` + * ```ignore * struct Foo; * * impl ::core::ops::Slice for Foo { @@ -749,7 +749,7 @@ pub trait Slice for Sized? { * A trivial implementation of `SliceMut`. When `Foo[Foo..]` happens, it ends up * calling `slice_from_mut`, and therefore, `main` prints `Slicing!`. * - * ``` + * ```ignore * struct Foo; * * impl ::core::ops::SliceMut for Foo { @@ -771,7 +771,7 @@ pub trait Slice for Sized? { * } * } * - * fn main() { + * pub fn main() { * Foo[mut Foo..]; * } * ``` diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 68b3a3199df..2ff0fd2ef00 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -814,13 +814,13 @@ impl<'a,T> MutableSlice<'a, T> for &'a mut [T] { #[inline] fn tail_mut(self) -> &'a mut [T] { let len = self.len(); - self.slice_mut(1, len) + self[mut 1..len] } #[inline] fn init_mut(self) -> &'a mut [T] { let len = self.len(); - self.slice_mut(0, len - 1) + self[mut 0..len - 1] } #[inline] diff --git a/src/libcoretest/lib.rs b/src/libcoretest/lib.rs index 7866d2f4a11..5f31ed35f1b 100644 --- a/src/libcoretest/lib.rs +++ b/src/libcoretest/lib.rs @@ -7,7 +7,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(globs, unsafe_destructor, macro_rules)] +#![feature(globs, unsafe_destructor, macro_rules, slicing_syntax)] extern crate core; extern crate test; diff --git a/src/libnative/lib.rs b/src/libnative/lib.rs index 267ff3d2a81..5def99d8ef3 100644 --- a/src/libnative/lib.rs +++ b/src/libnative/lib.rs @@ -57,7 +57,8 @@ #![deny(unused_result, unused_must_use)] #![allow(non_camel_case_types, deprecated)] -#![feature(default_type_params, lang_items)] +#![allow(unknown_features)] +#![feature(default_type_params, lang_items, slicing_syntax)] // NB this crate explicitly does *not* allow glob imports, please seriously // consider whether they're needed before adding that feature here (the diff --git a/src/libnum/lib.rs b/src/libnum/lib.rs index 17071d22dee..fa41cf37112 100644 --- a/src/libnum/lib.rs +++ b/src/libnum/lib.rs @@ -43,7 +43,8 @@ //! //! [newt]: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method -#![feature(macro_rules)] +#![allow(unknown_features)] +#![feature(macro_rules, slicing_syntax)] #![feature(default_type_params)] #![crate_name = "num"] diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index fa327fb3b4c..7480cf320cf 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -24,7 +24,8 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/master/", html_playground_url = "http://play.rust-lang.org/")] -#![feature(macro_rules, phase)] +#![allow(unknown_features)] +#![feature(macro_rules, phase, slicing_syntax)] #![allow(missing_doc)] extern crate serialize; diff --git a/src/libregex/lib.rs b/src/libregex/lib.rs index 9ff65fe3e2a..fdfd8c1eae2 100644 --- a/src/libregex/lib.rs +++ b/src/libregex/lib.rs @@ -368,7 +368,8 @@ html_root_url = "http://doc.rust-lang.org/master/", html_playground_url = "http://play.rust-lang.org/")] -#![feature(macro_rules, phase)] +#![allow(unknown_features)] +#![feature(macro_rules, phase, slicing_syntax)] #![deny(missing_doc)] #[cfg(test)] diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index be3867eaba2..478aa6d9805 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -29,8 +29,9 @@ This API is completely unstable and subject to change. html_root_url = "http://doc.rust-lang.org/master/")] #![allow(deprecated)] +#![allow(unknown_features)] #![feature(macro_rules, globs, struct_variant, quote)] -#![feature(default_type_params, phase, unsafe_destructor)] +#![feature(default_type_params, phase, unsafe_destructor, slicing_syntax)] #![feature(rustc_diagnostic_macros)] #![feature(import_shadowing)] diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index e48f9df7564..6486442deb8 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -31,7 +31,8 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/")] -#![feature(globs, phase, macro_rules)] +#![allow(unknown_features)] +#![feature(globs, phase, macro_rules, slicing_syntax)] #[phase(plugin, link)] extern crate log; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 71d00e50af8..b46d8727b69 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -15,7 +15,8 @@ #![crate_type = "dylib"] #![crate_type = "rlib"] -#![feature(globs, struct_variant, managed_boxes, macro_rules, phase)] +#![allow(unknown_features)] +#![feature(globs, struct_variant, managed_boxes, macro_rules, phase, slicing_syntax)] extern crate arena; extern crate debug; diff --git a/src/librustrt/lib.rs b/src/librustrt/lib.rs index 72c7d89a3b9..1183b14fb4e 100644 --- a/src/librustrt/lib.rs +++ b/src/librustrt/lib.rs @@ -16,9 +16,10 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/master/")] +#![allow(unknown_features)] #![feature(macro_rules, phase, globs, thread_local, managed_boxes, asm)] #![feature(linkage, lang_items, unsafe_destructor, default_type_params)] -#![feature(import_shadowing)] +#![feature(import_shadowing, slicing_syntax)] #![no_std] #![experimental] diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 5c35ad85233..8c2f3235322 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -23,7 +23,8 @@ Core encoding and decoding interfaces. html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/master/", html_playground_url = "http://play.rust-lang.org/")] -#![feature(macro_rules, managed_boxes, default_type_params, phase)] +#![allow(unknown_features)] +#![feature(macro_rules, managed_boxes, default_type_params, phase, slicing_syntax)] // test harness access #[cfg(test)] diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index 4dd6f448ee5..b8fb187548c 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -35,26 +35,29 @@ use rt::rtio; /// /// ```rust,no_run /// # #![allow(unused_must_use)] +/// #![feature(slicing_syntax)] +/// /// use std::io::net::udp::UdpSocket; /// use std::io::net::ip::{Ipv4Addr, SocketAddr}; +/// fn main() { +/// let addr = SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 34254 }; +/// let mut socket = match UdpSocket::bind(addr) { +/// Ok(s) => s, +/// Err(e) => fail!("couldn't bind socket: {}", e), +/// }; /// -/// let addr = SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 34254 }; -/// let mut socket = match UdpSocket::bind(addr) { -/// Ok(s) => s, -/// Err(e) => fail!("couldn't bind socket: {}", e), -/// }; -/// -/// let mut buf = [0, ..10]; -/// match socket.recv_from(buf) { -/// Ok((amt, src)) => { -/// // Send a reply to the socket we received data from -/// let buf = buf[mut ..amt]; -/// buf.reverse(); -/// socket.send_to(buf, src); +/// let mut buf = [0, ..10]; +/// match socket.recv_from(buf) { +/// Ok((amt, src)) => { +/// // Send a reply to the socket we received data from +/// let buf = buf[mut ..amt]; +/// buf.reverse(); +/// socket.send_to(buf, src); +/// } +/// Err(e) => println!("couldn't receive a datagram: {}", e) /// } -/// Err(e) => println!("couldn't receive a datagram: {}", e) +/// drop(socket); // close the socket /// } -/// drop(socket); // close the socket /// ``` pub struct UdpSocket { obj: Box, diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 7304871cf21..82de55efad6 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -105,9 +105,10 @@ html_root_url = "http://doc.rust-lang.org/master/", html_playground_url = "http://play.rust-lang.org/")] +#![allow(unknown_features)] #![feature(macro_rules, globs, managed_boxes, linkage)] #![feature(default_type_params, phase, lang_items, unsafe_destructor)] -#![feature(import_shadowing)] +#![feature(import_shadowing, slicing_syntax)] // Don't link to std. We are std. #![no_std] diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index ca6d488772c..38de2a9c284 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -70,6 +70,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[ ("tuple_indexing", Active), ("associated_types", Active), ("visible_private_types", Active), + ("slicing_syntax", Active), ("if_let", Active), @@ -362,6 +363,11 @@ impl<'a, 'v> Visitor<'v> for Context<'a> { self.gate_feature("if_let", e.span, "`if let` syntax is experimental"); } + ast::ExprSlice(..) => { + self.gate_feature("slicing_syntax", + e.span, + "slicing syntax is experimental"); + } _ => {} } visit::walk_expr(self, e); diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index a4271544146..64dedd45923 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -23,7 +23,8 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/master/")] -#![feature(macro_rules, globs, default_type_params, phase)] +#![allow(unknown_features)] +#![feature(macro_rules, globs, default_type_params, phase, slicing_syntax)] #![feature(quote, struct_variant, unsafe_destructor, import_shadowing)] #![allow(deprecated)] diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index 3fc631422d5..b05e0a4bff3 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -49,7 +49,8 @@ html_root_url = "http://doc.rust-lang.org/master/", html_playground_url = "http://play.rust-lang.org/")] -#![feature(macro_rules, phase)] +#![allow(unknown_features)] +#![feature(macro_rules, phase, slicing_syntax)] #![deny(missing_doc)] diff --git a/src/test/bench/shootout-fannkuch-redux.rs b/src/test/bench/shootout-fannkuch-redux.rs index 1260cc33725..b4292c2b050 100644 --- a/src/test/bench/shootout-fannkuch-redux.rs +++ b/src/test/bench/shootout-fannkuch-redux.rs @@ -38,6 +38,8 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED // OF THE POSSIBILITY OF SUCH DAMAGE. +#![feature(slicing_syntax)] + use std::{cmp, iter, mem}; use std::sync::Future; diff --git a/src/test/bench/shootout-fasta-redux.rs b/src/test/bench/shootout-fasta-redux.rs index 3f8c929aecf..b8af76ce17c 100644 --- a/src/test/bench/shootout-fasta-redux.rs +++ b/src/test/bench/shootout-fasta-redux.rs @@ -38,6 +38,8 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED // OF THE POSSIBILITY OF SUCH DAMAGE. +#![feature(slicing_syntax)] + use std::cmp::min; use std::io::{stdout, IoResult}; use std::os; diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index ed8ddcaa0ed..7565525bc8c 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -38,6 +38,8 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED // OF THE POSSIBILITY OF SUCH DAMAGE. +#![feature(slicing_syntax)] + use std::io; use std::io::{BufferedWriter, File}; use std::cmp::min; diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 80d623bbeb1..86c1bd82e9f 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -13,6 +13,8 @@ // multi tasking k-nucleotide +#![feature(slicing_syntax)] + extern crate collections; use std::collections::HashMap; diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index 70fd937d2a3..8c08fc4caa1 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -40,6 +40,8 @@ // ignore-android see #10393 #13206 +#![feature(slicing_syntax)] + use std::string::String; use std::slice; use std::sync::{Arc, Future}; diff --git a/src/test/bench/shootout-regex-dna.rs b/src/test/bench/shootout-regex-dna.rs index 0adb80c2689..dccdafe9cf8 100644 --- a/src/test/bench/shootout-regex-dna.rs +++ b/src/test/bench/shootout-regex-dna.rs @@ -41,7 +41,7 @@ // ignore-stage1 // ignore-cross-compile #12102 -#![feature(macro_rules, phase)] +#![feature(macro_rules, phase, slicing_syntax)] extern crate regex; #[phase(plugin)]extern crate regex_macros; diff --git a/src/test/bench/shootout-reverse-complement.rs b/src/test/bench/shootout-reverse-complement.rs index e5f22a3d07c..e3fa6334f77 100644 --- a/src/test/bench/shootout-reverse-complement.rs +++ b/src/test/bench/shootout-reverse-complement.rs @@ -41,6 +41,8 @@ // ignore-pretty very bad with line comments // ignore-android doesn't terminate? +#![feature(slicing_syntax)] + use std::iter::range_step; use std::io::{stdin, stdout, File}; diff --git a/src/test/compile-fail/issue-15730.rs b/src/test/compile-fail/issue-15730.rs index fc8c4e36075..c29e74af03c 100644 --- a/src/test/compile-fail/issue-15730.rs +++ b/src/test/compile-fail/issue-15730.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(slicing_syntax)] + fn main() { let mut array = [1, 2, 3]; //~^ ERROR cannot determine a type for this local variable: cannot determine the type of this integ diff --git a/src/test/compile-fail/slice-2.rs b/src/test/compile-fail/slice-2.rs index fbfc438321c..63f79c808ae 100644 --- a/src/test/compile-fail/slice-2.rs +++ b/src/test/compile-fail/slice-2.rs @@ -10,6 +10,8 @@ // Test that slicing syntax gives errors if we have not implemented the trait. +#![feature(slicing_syntax)] + struct Foo; fn main() { diff --git a/src/test/compile-fail/slice-borrow.rs b/src/test/compile-fail/slice-borrow.rs index 3d12511134f..00783b71ea1 100644 --- a/src/test/compile-fail/slice-borrow.rs +++ b/src/test/compile-fail/slice-borrow.rs @@ -10,6 +10,8 @@ // Test slicing expressions doesn't defeat the borrow checker. +#![feature(slicing_syntax)] + fn main() { let y; { diff --git a/src/test/compile-fail/slice-mut-2.rs b/src/test/compile-fail/slice-mut-2.rs index 1176b637cec..09019448a67 100644 --- a/src/test/compile-fail/slice-mut-2.rs +++ b/src/test/compile-fail/slice-mut-2.rs @@ -10,6 +10,8 @@ // Test mutability and slicing syntax. +#![feature(slicing_syntax)] + fn main() { let x: &[int] = &[1, 2, 3, 4, 5]; // Can't mutably slice an immutable slice diff --git a/src/test/compile-fail/slice-mut.rs b/src/test/compile-fail/slice-mut.rs index 8cd7c4ed0bb..cbfa3ed85fd 100644 --- a/src/test/compile-fail/slice-mut.rs +++ b/src/test/compile-fail/slice-mut.rs @@ -10,6 +10,8 @@ // Test mutability and slicing syntax. +#![feature(slicing_syntax)] + fn main() { let x: &[int] = &[1, 2, 3, 4, 5]; // Immutable slices are not mutable. diff --git a/src/test/debuginfo/vec-slices.rs b/src/test/debuginfo/vec-slices.rs index 392a025b1f0..67e621fe556 100644 --- a/src/test/debuginfo/vec-slices.rs +++ b/src/test/debuginfo/vec-slices.rs @@ -80,6 +80,7 @@ // lldb-check:[...]$5 = &[AStruct { x: 10, y: 11, z: 12 }, AStruct { x: 13, y: 14, z: 15 }] #![allow(unused_variable)] +#![feature(slicing_syntax)] struct AStruct { x: i16, diff --git a/src/test/run-pass/issue-3888-2.rs b/src/test/run-pass/issue-3888-2.rs index 20629673619..10add853ee7 100644 --- a/src/test/run-pass/issue-3888-2.rs +++ b/src/test/run-pass/issue-3888-2.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(slicing_syntax)] + fn vec_peek<'r, T>(v: &'r [T]) -> &'r [T] { v[1..5] } diff --git a/src/test/run-pass/issue-4464.rs b/src/test/run-pass/issue-4464.rs index 0f3f9149536..f2c1a715b51 100644 --- a/src/test/run-pass/issue-4464.rs +++ b/src/test/run-pass/issue-4464.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(slicing_syntax)] + fn broken(v: &[u8], i: uint, j: uint) -> &[u8] { v[i..j] } pub fn main() {} diff --git a/src/test/run-pass/issue-8898.rs b/src/test/run-pass/issue-8898.rs index 1838f34a9ab..f2dcaa4a31e 100644 --- a/src/test/run-pass/issue-8898.rs +++ b/src/test/run-pass/issue-8898.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(slicing_syntax)] extern crate debug; diff --git a/src/test/run-pass/slice-2.rs b/src/test/run-pass/slice-2.rs index 3c0933a055c..768c28cb8de 100644 --- a/src/test/run-pass/slice-2.rs +++ b/src/test/run-pass/slice-2.rs @@ -10,6 +10,8 @@ // Test slicing expressions on slices and Vecs. +#![feature(slicing_syntax)] + fn main() { let x: &[int] = &[1, 2, 3, 4, 5]; let cmp: &[int] = &[1, 2, 3, 4, 5]; diff --git a/src/test/run-pass/slice-fail-1.rs b/src/test/run-pass/slice-fail-1.rs index f6972023a72..b07cf595968 100644 --- a/src/test/run-pass/slice-fail-1.rs +++ b/src/test/run-pass/slice-fail-1.rs @@ -10,6 +10,8 @@ // Test that is a slicing expr[..] fails, the correct cleanups happen. +#![feature(slicing_syntax)] + use std::task; struct Foo; diff --git a/src/test/run-pass/slice-fail-2.rs b/src/test/run-pass/slice-fail-2.rs index cbe65fcd83d..a2aecc1d5cd 100644 --- a/src/test/run-pass/slice-fail-2.rs +++ b/src/test/run-pass/slice-fail-2.rs @@ -10,6 +10,8 @@ // Test that is a slicing expr[..] fails, the correct cleanups happen. +#![feature(slicing_syntax)] + use std::task; struct Foo; diff --git a/src/test/run-pass/slice.rs b/src/test/run-pass/slice.rs index 661ff055dc2..2b4251b4089 100644 --- a/src/test/run-pass/slice.rs +++ b/src/test/run-pass/slice.rs @@ -10,6 +10,8 @@ // Test slicing sugar. +#![feature(slicing_syntax)] + extern crate core; use core::ops::{Slice,SliceMut}; -- cgit 1.4.1-3-g733a5 From 6e0611a48707a1f5d90aee32a02b2b15957ef25b Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Tue, 30 Sep 2014 15:34:27 +1300 Subject: Review and rebasing changes --- src/libcollections/slice.rs | 3 +- src/libcollections/string.rs | 29 ++++++++++++++ src/libcollections/vec.rs | 15 +++---- src/libcore/slice.rs | 8 ++-- src/libcore/str.rs | 84 +++++++++++++++++++++++++++++----------- src/libnative/io/pipe_windows.rs | 2 +- src/libstd/os.rs | 2 +- src/libstd/rt/backtrace.rs | 2 +- 8 files changed, 103 insertions(+), 42 deletions(-) (limited to 'src/libstd') diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 60692ceb401..253375aabe8 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -44,7 +44,8 @@ //! //! A number of traits add methods that allow you to accomplish tasks with slices. //! These traits include `ImmutableSlice`, which is defined for `&[T]` types, -//! and `MutableSlice`, defined for `&mut [T]` types. +//! `MutableSlice`, defined for `&mut [T]` types, and `Slice` and `SliceMut` +//! which are defined for `[T]`. //! //! An example is the `slice` method which enables slicing syntax `[a..b]` that //! returns an immutable "view" into a `Vec` or another slice from the index diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 206e392f664..1032a504330 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -927,6 +927,7 @@ impl Add for String { } } +#[cfg(stage0)] impl ops::Slice for String { #[inline] fn as_slice_<'a>(&'a self) -> &'a str { @@ -949,6 +950,34 @@ impl ops::Slice for String { } } +#[cfg(not(stage0))] +#[inline] +fn str_to_slice<'a, U: Str>(this: &'a U) -> &'a str { + this.as_slice() +} +#[cfg(not(stage0))] +impl ops::Slice for String { + #[inline] + fn as_slice<'a>(&'a self) -> &'a str { + str_to_slice(self) + } + + #[inline] + fn slice_from<'a>(&'a self, from: &uint) -> &'a str { + self[][*from..] + } + + #[inline] + fn slice_to<'a>(&'a self, to: &uint) -> &'a str { + self[][..*to] + } + + #[inline] + fn slice<'a>(&'a self, from: &uint, to: &uint) -> &'a str { + self[][*from..*to] + } +} + /// Unsafe operations #[unstable = "waiting on raw module conventions"] pub mod raw { diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index ee6f5e840be..307ad383c2c 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -462,6 +462,7 @@ impl Index for Vec { // Annoying helper function because there are two Slice::as_slice functions in // scope. +#[cfg(not(stage0))] #[inline] fn slice_to_slice<'a, T, U: Slice>(this: &'a U) -> &'a [T] { this.as_slice() @@ -983,7 +984,6 @@ impl Vec { /// assert!(vec[0..2] == [1, 2]); /// ``` #[inline] - #[deprecated = "use slicing syntax"] pub fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [T] { self[start..end] } @@ -1019,7 +1019,7 @@ impl Vec { /// assert!(vec.tailn(2) == [3, 4]); /// ``` #[inline] - #[deprecated = "use slicing syntax"] + #[deprecated = "use slice_from"] pub fn tailn<'a>(&'a self, n: uint) -> &'a [T] { self[n..] } @@ -1229,7 +1229,7 @@ impl Vec { } /// Deprecated: use `slice_mut`. - #[deprecated = "use slicing syntax"] + #[deprecated = "use slice_from"] pub fn mut_slice<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [T] { self[mut start..end] @@ -1249,14 +1249,13 @@ impl Vec { /// assert!(vec[mut 0..2] == [1, 2]); /// ``` #[inline] - #[deprecated = "use slicing syntax"] pub fn slice_mut<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [T] { self[mut start..end] } /// Deprecated: use "slice_from_mut". - #[deprecated = "use slicing syntax"] + #[deprecated = "use slice_from_mut"] pub fn mut_slice_from<'a>(&'a mut self, start: uint) -> &'a mut [T] { self[mut start..] } @@ -1274,13 +1273,12 @@ impl Vec { /// assert!(vec[mut 2..] == [3, 4]); /// ``` #[inline] - #[deprecated = "use slicing syntax"] pub fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T] { self[mut start..] } /// Deprecated: use `slice_to_mut`. - #[deprecated = "use slicing syntax"] + #[deprecated = "use slice_to_mut"] pub fn mut_slice_to<'a>(&'a mut self, end: uint) -> &'a mut [T] { self[mut ..end] } @@ -1298,7 +1296,6 @@ impl Vec { /// assert!(vec[mut ..2] == [1, 2]); /// ``` #[inline] - #[deprecated = "use slicing syntax"] pub fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T] { self[mut ..end] } @@ -1375,7 +1372,6 @@ impl Vec { /// assert!(vec[1..] == [2, 3]); /// ``` #[inline] - #[deprecated = "use slicing syntax"] pub fn slice_from<'a>(&'a self, start: uint) -> &'a [T] { self[start..] } @@ -1393,7 +1389,6 @@ impl Vec { /// assert!(vec[..2] == [1, 2]); /// ``` #[inline] - #[deprecated = "use slicing syntax"] pub fn slice_to<'a>(&'a self, end: uint) -> &'a [T] { self[..end] } diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 2ff0fd2ef00..a8becb315b2 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -152,7 +152,7 @@ pub trait ImmutableSlice<'a, T> { fn tail(&self) -> &'a [T]; /// Returns all but the first `n' elements of a slice. - #[deprecated = "use slicing syntax"] + #[deprecated = "use slice_from"] fn tailn(&self, n: uint) -> &'a [T]; /// Returns all but the last element of a slice. @@ -161,7 +161,6 @@ pub trait ImmutableSlice<'a, T> { /// Returns all but the last `n' elements of a slice. #[deprecated = "use slice_to but note the arguments are different"] - #[deprecated = "use slicing syntax, but note the arguments are different"] fn initn(&self, n: uint) -> &'a [T]; /// Returns the last element of a slice, or `None` if it is empty. @@ -321,7 +320,7 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] { fn tail(&self) -> &'a [T] { (*self)[1..] } #[inline] - #[deprecated = "use slicing syntax"] + #[deprecated = "use slice_from"] fn tailn(&self, n: uint) -> &'a [T] { (*self)[n..] } #[inline] @@ -330,7 +329,7 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] { } #[inline] - #[deprecated = "use slicing syntax but note the arguments are different"] + #[deprecated = "use slice_to but note the arguments are different"] fn initn(&self, n: uint) -> &'a [T] { (*self)[..self.len() - n] } @@ -543,7 +542,6 @@ pub trait MutableSlice<'a, T> { fn get_mut(self, index: uint) -> Option<&'a mut T>; /// Work with `self` as a mut slice. /// Primarily intended for getting a &mut [T] from a [T, ..N]. - #[deprecated = "use slicing syntax"] fn as_mut_slice(self) -> &'a mut [T]; /// Deprecated: use `iter_mut`. diff --git a/src/libcore/str.rs b/src/libcore/str.rs index f3a10a0a3ae..1c20d364bf8 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1164,6 +1164,7 @@ pub mod traits { fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) } } + #[cfg(stage0)] impl ops::Slice for str { #[inline] fn as_slice_<'a>(&'a self) -> &'a str { @@ -1172,17 +1173,39 @@ pub mod traits { #[inline] fn slice_from_<'a>(&'a self, from: &uint) -> &'a str { - self.slice_from(*from) + super::slice_from_impl(&self, *from) } #[inline] fn slice_to_<'a>(&'a self, to: &uint) -> &'a str { - self.slice_to(*to) + super::slice_to_impl(&self, *to) } #[inline] fn slice_<'a>(&'a self, from: &uint, to: &uint) -> &'a str { - self.slice(*from, *to) + super::slice_impl(&self, *from, *to) + } + } + #[cfg(not(stage0))] + impl ops::Slice for str { + #[inline] + fn as_slice<'a>(&'a self) -> &'a str { + self + } + + #[inline] + fn slice_from<'a>(&'a self, from: &uint) -> &'a str { + super::slice_from_impl(&self, *from) + } + + #[inline] + fn slice_to<'a>(&'a self, to: &uint) -> &'a str { + super::slice_to_impl(&self, *to) + } + + #[inline] + fn slice<'a>(&'a self, from: &uint, to: &uint) -> &'a str { + super::slice_impl(&self, *from, *to) } } } @@ -1835,6 +1858,38 @@ fn slice_error_fail(s: &str, begin: uint, end: uint) -> ! { begin, end, s); } +#[inline] +fn slice_impl<'a>(this: &&'a str, begin: uint, end: uint) -> &'a str { + // is_char_boundary checks that the index is in [0, .len()] + if begin <= end && + this.is_char_boundary(begin) && + this.is_char_boundary(end) { + unsafe { raw::slice_unchecked(*this, begin, end) } + } else { + slice_error_fail(*this, begin, end) + } +} + +#[inline] +fn slice_from_impl<'a>(this: &&'a str, begin: uint) -> &'a str { + // is_char_boundary checks that the index is in [0, .len()] + if this.is_char_boundary(begin) { + unsafe { raw::slice_unchecked(*this, begin, this.len()) } + } else { + slice_error_fail(*this, begin, this.len()) + } +} + +#[inline] +fn slice_to_impl<'a>(this: &&'a str, end: uint) -> &'a str { + // is_char_boundary checks that the index is in [0, .len()] + if this.is_char_boundary(end) { + unsafe { raw::slice_unchecked(*this, 0, end) } + } else { + slice_error_fail(*this, 0, end) + } +} + impl<'a> StrSlice<'a> for &'a str { #[inline] fn contains<'a>(&self, needle: &'a str) -> bool { @@ -1938,34 +1993,17 @@ impl<'a> StrSlice<'a> for &'a str { #[inline] fn slice(&self, begin: uint, end: uint) -> &'a str { - // is_char_boundary checks that the index is in [0, .len()] - if begin <= end && - self.is_char_boundary(begin) && - self.is_char_boundary(end) { - unsafe { raw::slice_unchecked(*self, begin, end) } - } else { - slice_error_fail(*self, begin, end) - } + slice_impl(self, begin, end) } #[inline] fn slice_from(&self, begin: uint) -> &'a str { - // is_char_boundary checks that the index is in [0, .len()] - if self.is_char_boundary(begin) { - unsafe { raw::slice_unchecked(*self, begin, self.len()) } - } else { - slice_error_fail(*self, begin, self.len()) - } + slice_from_impl(self, begin) } #[inline] fn slice_to(&self, end: uint) -> &'a str { - // is_char_boundary checks that the index is in [0, .len()] - if self.is_char_boundary(end) { - unsafe { raw::slice_unchecked(*self, 0, end) } - } else { - slice_error_fail(*self, 0, end) - } + slice_to_impl(self, end) } fn slice_chars(&self, begin: uint, end: uint) -> &'a str { diff --git a/src/libnative/io/pipe_windows.rs b/src/libnative/io/pipe_windows.rs index 2de9cd9a41c..5475de6d7e1 100644 --- a/src/libnative/io/pipe_windows.rs +++ b/src/libnative/io/pipe_windows.rs @@ -448,7 +448,7 @@ impl rtio::RtioPipe for UnixStream { } let ret = unsafe { libc::WriteFile(self.handle(), - buf.slice_from(offset).as_ptr() as libc::LPVOID, + buf[offset..].as_ptr() as libc::LPVOID, (buf.len() - offset) as libc::DWORD, &mut bytes_written, &mut overlapped) diff --git a/src/libstd/os.rs b/src/libstd/os.rs index d904e657e40..c6948cccafe 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -144,7 +144,7 @@ pub mod windows { use option::{None, Option}; use option; use os::TMPBUF_SZ; - use slice::{MutableSlice, ImmutableSlice}; + use slice::MutableSlice; use string::String; use str::StrSlice; use vec::Vec; diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index 33f8713e1a1..e1925fc79d0 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -999,7 +999,7 @@ mod imp { let bytes = cstr.as_bytes(); match cstr.as_str() { Some(s) => try!(super::demangle(w, s)), - None => try!(w.write(bytes.slice_to(bytes.len() - 1))), + None => try!(w.write(bytes[..bytes.len()-1])), } } try!(w.write(['\n' as u8])); -- cgit 1.4.1-3-g733a5