1
Fork 0

Make unexpected always "return" PResult<()> & add unexpected_any

This prevents breakage when `?` no longer skews inference.
This commit is contained in:
Maybe Waffle 2024-03-15 11:36:21 +00:00
parent ee03c286cf
commit defcc44238
7 changed files with 25 additions and 15 deletions

View file

@ -465,7 +465,9 @@ impl<'a> Parser<'a> {
matches!(self.recovery, Recovery::Allowed)
}
pub fn unexpected<T>(&mut self) -> PResult<'a, T> {
/// Version of [`unexpected`](Parser::unexpected) that "returns" any type in the `Ok`
/// (both those functions never return "Ok", and so can lie like that in the type).
pub fn unexpected_any<T>(&mut self) -> PResult<'a, T> {
match self.expect_one_of(&[], &[]) {
Err(e) => Err(e),
// We can get `Ok(true)` from `recover_closing_delimiter`
@ -474,6 +476,10 @@ impl<'a> Parser<'a> {
}
}
pub fn unexpected(&mut self) -> PResult<'a, ()> {
self.unexpected_any()
}
/// Expects and consumes the token `t`. Signals an error if the next token is not `t`.
pub fn expect(&mut self, t: &TokenKind) -> PResult<'a, Recovered> {
if self.expected_tokens.is_empty() {
@ -1278,7 +1284,11 @@ impl<'a> Parser<'a> {
}
fn parse_delim_args(&mut self) -> PResult<'a, P<DelimArgs>> {
if let Some(args) = self.parse_delim_args_inner() { Ok(P(args)) } else { self.unexpected() }
if let Some(args) = self.parse_delim_args_inner() {
Ok(P(args))
} else {
self.unexpected_any()
}
}
fn parse_attr_args(&mut self) -> PResult<'a, AttrArgs> {