Invalid-length when enum seq is too short

This commit is contained in:
David Tolnay
2016-07-05 00:52:19 -07:00
parent c0e8164792
commit 1a449bb3d0
2 changed files with 34 additions and 3 deletions
+6 -3
View File
@@ -395,6 +395,7 @@ fn deserialize_seq(
fields: &[Field],
is_struct: bool,
) -> P<ast::Expr> {
let mut index_in_seq = 0usize;
let let_values: Vec<_> = fields.iter()
.enumerate()
.map(|(i, field)| {
@@ -420,14 +421,16 @@ fn deserialize_seq(
})
}
};
quote_stmt!(cx,
let assign = quote_stmt!(cx,
let $name = match $visit {
Some(value) => { value },
None => {
return Err(_serde::de::Error::end_of_stream());
return Err(_serde::de::Error::invalid_length($index_in_seq));
}
};
).unwrap()
).unwrap();
index_in_seq += 1;
assign
}
})
.collect();