Relax impls for [T; 0]

This commit is contained in:
David Tolnay 2017-04-05 17:34:13 -07:00
parent 2fe67d3d72
commit 6388019ad4
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
3 changed files with 18 additions and 7 deletions

View File

@ -625,9 +625,7 @@ impl<A> ArrayVisitor<A> {
}
}
impl<'de, T> Visitor<'de> for ArrayVisitor<[T; 0]>
where T: Deserialize<'de>
{
impl<'de, T> Visitor<'de> for ArrayVisitor<[T; 0]> {
type Value = [T; 0];
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
@ -642,9 +640,8 @@ impl<'de, T> Visitor<'de> for ArrayVisitor<[T; 0]>
}
}
impl<'de, T> Deserialize<'de> for [T; 0]
where T: Deserialize<'de>
{
// Does not require T: Deserialize<'de>.
impl<'de, T> Deserialize<'de> for [T; 0] {
fn deserialize<D>(deserializer: D) -> Result<[T; 0], D::Error>
where D: Deserializer<'de>
{

View File

@ -143,6 +143,16 @@ impl<T> Serialize for PhantomData<T> {
///////////////////////////////////////////////////////////////////////////////
// Does not require T: Serialize.
impl<T> Serialize for [T; 0] {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer
{
try!(serializer.serialize_seq_fixed_size(0)).end()
}
}
macro_rules! array_impls {
($len:expr) => {
impl<T> Serialize for [T; $len] where T: Serialize {
@ -160,7 +170,6 @@ macro_rules! array_impls {
}
}
array_impls!(0);
array_impls!(1);
array_impls!(2);
array_impls!(3);

View File

@ -295,6 +295,11 @@ fn test_gen() {
#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
struct UnitDenyUnknown;
#[derive(Serialize, Deserialize)]
struct EmptyArray {
empty: [X; 0],
}
}
//////////////////////////////////////////////////////////////////////////