MapVisitor::end and SeqVisitor::end were mostly never called

This commit is contained in:
Oliver Schneider 2015-03-16 13:20:34 +01:00
parent f4f8194f46
commit f21cbb71e2
4 changed files with 22 additions and 10 deletions

View File

@ -731,6 +731,9 @@ fn deserialize_map(
} }
$extract_values $extract_values
try!(visitor.end());
Ok($result) Ok($result)
}) })
} }

View File

@ -629,6 +629,8 @@ impl<T> Visitor for VecVisitor<T> where T: Deserialize {
values.push(value); values.push(value);
} }
try!(visitor.end());
Ok(values) Ok(values)
} }
} }
@ -735,6 +737,8 @@ impl<K, V> Visitor for HashMapVisitor<K, V>
values.insert(key, value); values.insert(key, value);
} }
try!(visitor.end());
Ok(values) Ok(values)
} }
} }
@ -781,6 +785,8 @@ impl<K, V> Visitor for BTreeMapVisitor<K, V>
values.insert(key, value); values.insert(key, value);
} }
try!(visitor.end());
Ok(values) Ok(values)
} }
} }

View File

@ -466,7 +466,6 @@ impl<'a, Iter> de::SeqVisitor for SeqVisitor<'a, Iter>
self.de.parse_whitespace(); self.de.parse_whitespace();
if self.de.ch_is(b']') { if self.de.ch_is(b']') {
self.de.bump();
return Ok(None); return Ok(None);
} }
@ -525,7 +524,6 @@ impl<'a, Iter> de::MapVisitor for MapVisitor<'a, Iter>
self.de.parse_whitespace(); self.de.parse_whitespace();
if self.de.ch_is(b'}') { if self.de.ch_is(b'}') {
self.de.bump();
return Ok(None); return Ok(None);
} }
@ -565,11 +563,11 @@ impl<'a, Iter> de::MapVisitor for MapVisitor<'a, Iter>
fn end(&mut self) -> Result<(), Error> { fn end(&mut self) -> Result<(), Error> {
self.de.parse_whitespace(); self.de.parse_whitespace();
if self.de.ch_is(b']') { if self.de.ch_is(b'}') {
self.de.bump(); self.de.bump();
Ok(()) Ok(())
} else if self.de.eof() { } else if self.de.eof() {
Err(self.de.error(ErrorCode::EOFWhileParsingList)) Err(self.de.error(ErrorCode::EOFWhileParsingObject))
} else { } else {
Err(self.de.error(ErrorCode::TrailingCharacters)) Err(self.de.error(ErrorCode::TrailingCharacters))
} }

View File

@ -184,12 +184,13 @@ impl<'a, 'b> de::SeqVisitor for TokenDeserializerSeqVisitor<'a, 'b> {
let first = self.first; let first = self.first;
self.first = false; self.first = false;
match self.de.tokens.next() { match self.de.tokens.peek() {
Some(Token::SeqSep(first_)) if first_ == first => { Some(&Token::SeqSep(first_)) if first_ == first => {
self.len -= 1; self.len -= 1;
self.de.tokens.next();
Ok(Some(try!(Deserialize::deserialize(self.de)))) Ok(Some(try!(Deserialize::deserialize(self.de))))
} }
Some(Token::SeqEnd) => Ok(None), Some(&Token::SeqEnd) => Ok(None),
Some(_) => { Some(_) => {
Err(Error::SyntaxError) Err(Error::SyntaxError)
} }
@ -198,6 +199,7 @@ impl<'a, 'b> de::SeqVisitor for TokenDeserializerSeqVisitor<'a, 'b> {
} }
fn end(&mut self) -> Result<(), Error> { fn end(&mut self) -> Result<(), Error> {
assert_eq!(self.len, 0);
match self.de.tokens.next() { match self.de.tokens.next() {
Some(Token::SeqEnd) => Ok(()), Some(Token::SeqEnd) => Ok(()),
Some(_) => Err(Error::SyntaxError), Some(_) => Err(Error::SyntaxError),
@ -227,11 +229,13 @@ impl<'a, 'b> de::MapVisitor for TokenDeserializerMapVisitor<'a, 'b> {
let first = self.first; let first = self.first;
self.first = false; self.first = false;
match self.de.tokens.next() { match self.de.tokens.peek() {
Some(Token::MapSep(first_)) if first_ == first => { Some(&Token::MapSep(first_)) if first_ == first => {
self.de.tokens.next();
self.len -= 1;
Ok(Some(try!(Deserialize::deserialize(self.de)))) Ok(Some(try!(Deserialize::deserialize(self.de))))
} }
Some(Token::MapEnd) => Ok(None), Some(&Token::MapEnd) => Ok(None),
Some(_) => Err(Error::SyntaxError), Some(_) => Err(Error::SyntaxError),
None => Err(Error::EndOfStreamError), None => Err(Error::EndOfStreamError),
} }
@ -244,6 +248,7 @@ impl<'a, 'b> de::MapVisitor for TokenDeserializerMapVisitor<'a, 'b> {
} }
fn end(&mut self) -> Result<(), Error> { fn end(&mut self) -> Result<(), Error> {
assert_eq!(self.len, 0);
match self.de.tokens.next() { match self.de.tokens.next() {
Some(Token::MapEnd) => Ok(()), Some(Token::MapEnd) => Ok(()),
Some(_) => Err(Error::SyntaxError), Some(_) => Err(Error::SyntaxError),