mirror of
https://github.com/allankoechke/rust.git
synced 2026-11-30 11:05:36 +00:00
Rollup merge of #161796 - fmease:rm-dead-underscore-recovery, r=mu001999
Remove dead parse error recovery (underscores in expressions)
Back in b7f7756566 (2019) the parser was extended to recover from `_`s as elements of tuple expressions (this was later extended to also cover call expressions). At the time, `_` obviously wasn't an expression yet.
Nowadays `parse_expr_res` will *always* successfully parse `_` as an `ExprKind::Underscore` (irrespective of the passed `Restrictions`). Consequently, we will never reach the special case in `parse_expr_catch_underscore`. Drop this entire wrapper function.
<sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
This commit is contained in:
@@ -85,30 +85,9 @@ impl<'a> Parser<'a> {
|
||||
self.parse_expr().map(|value| AnonConst { id: DUMMY_NODE_ID, value })
|
||||
}
|
||||
|
||||
fn parse_expr_catch_underscore(
|
||||
&mut self,
|
||||
restrictions: Restrictions,
|
||||
) -> PResult<'a, Box<Expr>> {
|
||||
match self.parse_expr_res(restrictions) {
|
||||
Ok(expr) => Ok(expr),
|
||||
Err(err) => match self.token.ident() {
|
||||
Some((Ident { name: kw::Underscore, .. }, IdentIsRaw::No))
|
||||
if self.may_recover() && self.look_ahead(1, |t| t == &token::Comma) =>
|
||||
{
|
||||
// Special-case handling of `foo(_, _, _)`
|
||||
let guar = err.emit();
|
||||
self.bump();
|
||||
Ok(self.mk_expr(self.prev_token.span, ExprKind::Err(guar)))
|
||||
}
|
||||
_ => Err(err),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses a sequence of expressions delimited by parentheses.
|
||||
fn parse_expr_paren_seq(&mut self) -> PResult<'a, ThinVec<Box<Expr>>> {
|
||||
self.parse_paren_comma_seq(|p| p.parse_expr_catch_underscore(Restrictions::empty()))
|
||||
.map(|(r, _)| r)
|
||||
self.parse_paren_comma_seq(Self::parse_expr).map(|(r, _)| r)
|
||||
}
|
||||
|
||||
/// Parses an expression, subject to the given restrictions.
|
||||
@@ -1644,7 +1623,7 @@ impl<'a> Parser<'a> {
|
||||
let (es, trailing_comma) = match self.parse_seq_to_end(
|
||||
exp!(CloseParen),
|
||||
SeqSep::trailing_allowed(exp!(Comma)),
|
||||
|p| p.parse_expr_catch_underscore(restrictions.intersection(Restrictions::ALLOW_LET)),
|
||||
|p| p.parse_expr_res(restrictions.intersection(Restrictions::ALLOW_LET)),
|
||||
) {
|
||||
Ok(x) => x,
|
||||
Err(err) => {
|
||||
|
||||
Reference in New Issue
Block a user