Skip to content

Commit

Permalink
Remove the newly introduced trait impls for fixed-size arrays and use…
Browse files Browse the repository at this point in the history
… &b"..."[..] instead.
  • Loading branch information
petrochenkov committed Mar 18, 2015
1 parent d2cccd0 commit dccd17d
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 175 deletions.
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/debuginfo.rs
Expand Up @@ -4054,7 +4054,7 @@ fn namespace_for_item(cx: &CrateContext, def_id: ast::DefId) -> Rc<NamespaceTree
/// .debug_gdb_scripts global is referenced, so it isn't removed by the linker.
pub fn insert_reference_to_gdb_debug_scripts_section_global(ccx: &CrateContext) {
if needs_gdb_debug_scripts_section(ccx) {
let empty = CString::new(b"").unwrap();
let empty = CString::new("").unwrap();
let gdb_debug_scripts_section_global =
get_or_insert_gdb_debug_scripts_section_global(ccx);
unsafe {
Expand Down
12 changes: 4 additions & 8 deletions src/libstd/ffi/c_str.rs
Expand Up @@ -11,7 +11,6 @@
#![unstable(feature = "std_misc")]

use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
use core::array::FixedSizeArray;
use error::{Error, FromError};
use fmt;
use io;
Expand Down Expand Up @@ -59,7 +58,7 @@ use vec::Vec;
/// fn my_printer(s: *const libc::c_char);
/// }
///
/// let to_print = b"Hello, world!";
/// let to_print = &b"Hello, world!"[..];
/// let c_to_print = CString::new(to_print).unwrap();
/// unsafe {
/// my_printer(c_to_print.as_ptr());
Expand Down Expand Up @@ -451,9 +450,6 @@ impl IntoBytes for String {
impl IntoBytes for Vec<u8> {
fn into_bytes(self) -> Vec<u8> { self }
}
impl<'a, T: FixedSizeArray<u8>> IntoBytes for &'a T {
fn into_bytes(self) -> Vec<u8> { self.as_slice().to_vec() }
}

#[cfg(test)]
mod tests {
Expand All @@ -473,14 +469,14 @@ mod tests {

#[test]
fn simple() {
let s = CString::new(b"1234").unwrap();
let s = CString::new("1234").unwrap();
assert_eq!(s.as_bytes(), b"1234");
assert_eq!(s.as_bytes_with_nul(), b"1234\0");
}

#[test]
fn build_with_zero1() {
assert!(CString::new(b"\0").is_err());
assert!(CString::new(&b"\0"[..]).is_err());
}
#[test]
fn build_with_zero2() {
Expand All @@ -497,7 +493,7 @@ mod tests {

#[test]
fn formatted() {
let s = CString::new(b"12").unwrap();
let s = CString::new(&b"12"[..]).unwrap();
assert_eq!(format!("{:?}", s), "\"12\"");
}

Expand Down
14 changes: 5 additions & 9 deletions src/libstd/io/cursor.rs
Expand Up @@ -11,7 +11,6 @@
use prelude::v1::*;
use io::prelude::*;

use core::array::FixedSizeArray;
use cmp;
use io::{self, SeekFrom, Error, ErrorKind};
use iter::repeat;
Expand Down Expand Up @@ -73,7 +72,7 @@ macro_rules! seek {
fn seek(&mut self, style: SeekFrom) -> io::Result<u64> {
let pos = match style {
SeekFrom::Start(n) => { self.pos = n; return Ok(n) }
SeekFrom::End(n) => self.inner.as_slice().len() as i64 + n,
SeekFrom::End(n) => self.inner.len() as i64 + n,
SeekFrom::Current(n) => self.pos as i64 + n,
};

Expand All @@ -95,7 +94,6 @@ impl<'a> io::Seek for Cursor<&'a [u8]> { seek!(); }
impl<'a> io::Seek for Cursor<&'a mut [u8]> { seek!(); }
#[stable(feature = "rust1", since = "1.0.0")]
impl io::Seek for Cursor<Vec<u8>> { seek!(); }
impl<'a, T: FixedSizeArray<u8>> io::Seek for Cursor<&'a T> { seek!(); }

macro_rules! read {
() => {
Expand All @@ -113,13 +111,12 @@ impl<'a> Read for Cursor<&'a [u8]> { read!(); }
impl<'a> Read for Cursor<&'a mut [u8]> { read!(); }
#[stable(feature = "rust1", since = "1.0.0")]
impl Read for Cursor<Vec<u8>> { read!(); }
impl<'a, T: FixedSizeArray<u8>> Read for Cursor<&'a T> { read!(); }

macro_rules! buffer {
() => {
fn fill_buf(&mut self) -> io::Result<&[u8]> {
let amt = cmp::min(self.pos, self.inner.as_slice().len() as u64);
Ok(&self.inner.as_slice()[(amt as usize)..])
let amt = cmp::min(self.pos, self.inner.len() as u64);
Ok(&self.inner[(amt as usize)..])
}
fn consume(&mut self, amt: usize) { self.pos += amt as u64; }
}
Expand All @@ -131,7 +128,6 @@ impl<'a> BufRead for Cursor<&'a [u8]> { buffer!(); }
impl<'a> BufRead for Cursor<&'a mut [u8]> { buffer!(); }
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> BufRead for Cursor<Vec<u8>> { buffer!(); }
impl<'a, T: FixedSizeArray<u8>> BufRead for Cursor<&'a T> { buffer!(); }

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Write for Cursor<&'a mut [u8]> {
Expand Down Expand Up @@ -332,7 +328,7 @@ mod tests {

#[test]
fn test_read_char() {
let b = b"Vi\xE1\xBB\x87t";
let b = &b"Vi\xE1\xBB\x87t"[..];
let mut c = Cursor::new(b).chars();
assert_eq!(c.next(), Some(Ok('V')));
assert_eq!(c.next(), Some(Ok('i')));
Expand All @@ -343,7 +339,7 @@ mod tests {

#[test]
fn test_read_bad_char() {
let b = b"\x80";
let b = &b"\x80"[..];
let mut c = Cursor::new(b).chars();
assert!(c.next().unwrap().is_err());
}
Expand Down
26 changes: 13 additions & 13 deletions src/libstd/io/mod.rs
Expand Up @@ -933,12 +933,12 @@ mod tests {

#[test]
fn read_until() {
let mut buf = Cursor::new(b"12");
let mut buf = Cursor::new(&b"12"[..]);
let mut v = Vec::new();
assert_eq!(buf.read_until(b'3', &mut v), Ok(2));
assert_eq!(v, b"12");

let mut buf = Cursor::new(b"1233");
let mut buf = Cursor::new(&b"1233"[..]);
let mut v = Vec::new();
assert_eq!(buf.read_until(b'3', &mut v), Ok(3));
assert_eq!(v, b"123");
Expand All @@ -952,12 +952,12 @@ mod tests {

#[test]
fn split() {
let buf = Cursor::new(b"12");
let buf = Cursor::new(&b"12"[..]);
let mut s = buf.split(b'3');
assert_eq!(s.next(), Some(Ok(vec![b'1', b'2'])));
assert_eq!(s.next(), None);

let buf = Cursor::new(b"1233");
let buf = Cursor::new(&b"1233"[..]);
let mut s = buf.split(b'3');
assert_eq!(s.next(), Some(Ok(vec![b'1', b'2'])));
assert_eq!(s.next(), Some(Ok(vec![])));
Expand All @@ -966,12 +966,12 @@ mod tests {

#[test]
fn read_line() {
let mut buf = Cursor::new(b"12");
let mut buf = Cursor::new(&b"12"[..]);
let mut v = String::new();
assert_eq!(buf.read_line(&mut v), Ok(2));
assert_eq!(v, "12");

let mut buf = Cursor::new(b"12\n\n");
let mut buf = Cursor::new(&b"12\n\n"[..]);
let mut v = String::new();
assert_eq!(buf.read_line(&mut v), Ok(3));
assert_eq!(v, "12\n");
Expand All @@ -985,12 +985,12 @@ mod tests {

#[test]
fn lines() {
let buf = Cursor::new(b"12");
let buf = Cursor::new(&b"12"[..]);
let mut s = buf.lines();
assert_eq!(s.next(), Some(Ok("12".to_string())));
assert_eq!(s.next(), None);

let buf = Cursor::new(b"12\n\n");
let buf = Cursor::new(&b"12\n\n"[..]);
let mut s = buf.lines();
assert_eq!(s.next(), Some(Ok("12".to_string())));
assert_eq!(s.next(), Some(Ok(String::new())));
Expand All @@ -999,30 +999,30 @@ mod tests {

#[test]
fn read_to_end() {
let mut c = Cursor::new(b"");
let mut c = Cursor::new(&b""[..]);
let mut v = Vec::new();
assert_eq!(c.read_to_end(&mut v), Ok(0));
assert_eq!(v, []);

let mut c = Cursor::new(b"1");
let mut c = Cursor::new(&b"1"[..]);
let mut v = Vec::new();
assert_eq!(c.read_to_end(&mut v), Ok(1));
assert_eq!(v, b"1");
}

#[test]
fn read_to_string() {
let mut c = Cursor::new(b"");
let mut c = Cursor::new(&b""[..]);
let mut v = String::new();
assert_eq!(c.read_to_string(&mut v), Ok(0));
assert_eq!(v, "");

let mut c = Cursor::new(b"1");
let mut c = Cursor::new(&b"1"[..]);
let mut v = String::new();
assert_eq!(c.read_to_string(&mut v), Ok(1));
assert_eq!(v, "1");

let mut c = Cursor::new(b"\xff");
let mut c = Cursor::new(&b"\xff"[..]);
let mut v = String::new();
assert!(c.read_to_string(&mut v).is_err());
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/old_io/process.rs
Expand Up @@ -1231,7 +1231,7 @@ mod tests {
cmd.env("path", "foo");
cmd.env("Path", "bar");
let env = &cmd.env.unwrap();
let val = env.get(&EnvKey(CString::new(b"PATH").unwrap()));
assert!(val.unwrap() == &CString::new(b"bar").unwrap());
let val = env.get(&EnvKey(CString::new("PATH").unwrap()));
assert!(val.unwrap() == &CString::new("bar").unwrap());
}
}
8 changes: 0 additions & 8 deletions src/libstd/old_path/mod.rs
Expand Up @@ -64,7 +64,6 @@
#![allow(deprecated)] // seriously this is all deprecated
#![allow(unused_imports)]

use core::array::FixedSizeArray;
use core::marker::Sized;
use ffi::CString;
use clone::Clone;
Expand Down Expand Up @@ -896,13 +895,6 @@ impl BytesContainer for [u8] {
}
}

impl<T: FixedSizeArray<u8>> BytesContainer for T {
#[inline]
fn container_as_bytes(&self) -> &[u8] {
self.as_slice()
}
}

impl BytesContainer for Vec<u8> {
#[inline]
fn container_as_bytes(&self) -> &[u8] {
Expand Down

0 comments on commit dccd17d

Please sign in to comment.