Skip to content

Commit 0c8a8a9

Browse files
committed
parse_entirely should not prioritize EndOfInput errors.
1 parent f71a5a2 commit 0c8a8a9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/parser.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,9 @@ impl<'i: 't, 't> Parser<'i, 't> {
364364
#[inline]
365365
pub fn parse_entirely<F, T, E>(&mut self, parse: F) -> Result<T, ParseError<'i, E>>
366366
where F: FnOnce(&mut Parser<'i, 't>) -> Result<T, ParseError<'i, E>> {
367-
let result = parse(self);
367+
let result = parse(self)?;
368368
self.expect_exhausted()?;
369-
result
369+
Ok(result)
370370
}
371371

372372
/// Parse a list of comma-separated values, all with the same syntax.

src/tests.rs

+10
Original file line numberDiff line numberDiff line change
@@ -939,3 +939,13 @@ fn parser_maintains_current_line() {
939939
assert_eq!(parser.next(), Ok(Token::Ident("ident".into())));
940940
assert_eq!(parser.current_line(), "ident");
941941
}
942+
943+
#[test]
944+
fn parse_entirely_reports_first_error() {
945+
#[derive(PartialEq, Debug)]
946+
enum E { Foo }
947+
let mut input = ParserInput::new("ident");
948+
let mut parser = Parser::new(&mut input);
949+
let result: Result<(), _> = parser.parse_entirely(|_| Err(ParseError::Custom(E::Foo)));
950+
assert_eq!(result, Err(ParseError::Custom(E::Foo)));
951+
}

0 commit comments

Comments
 (0)