diff --git a/compiler/rustc_serialize/src/lib.rs b/compiler/rustc_serialize/src/lib.rs index ed48fbf40ac..fab29f29e87 100644 --- a/compiler/rustc_serialize/src/lib.rs +++ b/compiler/rustc_serialize/src/lib.rs @@ -13,6 +13,7 @@ #![feature(never_type)] #![feature(nll)] #![feature(associated_type_bounds)] +#![feature(min_const_generics)] #![cfg_attr(test, feature(test))] #![allow(rustc::internal)] diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs index c0e23b89a60..aa305f3c7fc 100644 --- a/compiler/rustc_serialize/src/serialize.rs +++ b/compiler/rustc_serialize/src/serialize.rs @@ -539,12 +539,8 @@ fn encode(&self, s: &mut S) -> Result<(), S::Error> { impl> Encodable for Vec { fn encode(&self, s: &mut S) -> Result<(), S::Error> { - s.emit_seq(self.len(), |s| { - for (i, e) in self.iter().enumerate() { - s.emit_seq_elt(i, |s| e.encode(s))? - } - Ok(()) - }) + let slice: &[T] = self; + slice.encode(s) } } @@ -560,22 +556,18 @@ fn decode(d: &mut D) -> Result, D::Error> { } } -impl Encodable for [u8; 20] { +impl, const N: usize> Encodable for [T; N] { fn encode(&self, s: &mut S) -> Result<(), S::Error> { - s.emit_seq(self.len(), |s| { - for (i, e) in self.iter().enumerate() { - s.emit_seq_elt(i, |s| e.encode(s))? - } - Ok(()) - }) + let slice: &[T] = self; + slice.encode(s) } } -impl Decodable for [u8; 20] { - fn decode(d: &mut D) -> Result<[u8; 20], D::Error> { +impl Decodable for [u8; N] { + fn decode(d: &mut D) -> Result<[u8; N], D::Error> { d.read_seq(|d, len| { - assert!(len == 20); - let mut v = [0u8; 20]; + assert!(len == N); + let mut v = [0u8; N]; for i in 0..len { v[i] = d.read_seq_elt(i, |d| Decodable::decode(d))?; } @@ -589,12 +581,8 @@ impl<'a, S: Encoder, T: Encodable> Encodable for Cow<'a, [T]> [T]: ToOwned>, { fn encode(&self, s: &mut S) -> Result<(), S::Error> { - s.emit_seq(self.len(), |s| { - for (i, e) in self.iter().enumerate() { - s.emit_seq_elt(i, |s| e.encode(s))? - } - Ok(()) - }) + let slice: &[T] = self; + slice.encode(s) } }