Skip to content

Commit

Permalink
Rollup merge of #119359 - DaniPopes:ident-or-err, r=compiler-errors
Browse files Browse the repository at this point in the history
Simplify Parser::ident_or_error

Avoid a nested `Result<T, PResult<T>>`.
  • Loading branch information
matthiaskrgr committed Dec 28, 2023
2 parents 2f51bad + 826269e commit 54bcb07
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions compiler/rustc_parse/src/parser/mod.rs
Expand Up @@ -504,18 +504,10 @@ impl<'a> Parser<'a> {
}

fn ident_or_err(&mut self, recover: bool) -> PResult<'a, (Ident, /* is_raw */ bool)> {
let result = self.token.ident().ok_or_else(|| self.expected_ident_found(recover));

let (ident, is_raw) = match result {
Ok(ident) => ident,
Err(err) => match err {
// we recovered!
Ok(ident) => ident,
Err(err) => return Err(err),
},
};

Ok((ident, is_raw))
match self.token.ident() {
Some(ident) => Ok(ident),
None => self.expected_ident_found(recover),
}
}

/// Checks if the next token is `tok`, and returns `true` if so.
Expand Down

0 comments on commit 54bcb07

Please sign in to comment.