Rollup merge of #134161 - nnethercote:overhaul-token-cursors, r=spastorino

Overhaul token cursors

Some nice cleanups here.

r? `````@davidtwco`````
This commit is contained in:
许杰友 Jieyou Xu (Joe) 2024-12-18 22:56:53 +08:00 committed by GitHub
commit 477f222b02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 199 additions and 210 deletions

View file

@ -8,6 +8,7 @@ use ast::token::IdentIsRaw;
use ast::{CoroutineKind, ForLoopKind, GenBlockKind, MatchKind, Pat, Path, PathSegment, Recovered};
use rustc_ast::ptr::P;
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
use rustc_ast::tokenstream::TokenTree;
use rustc_ast::util::case::Case;
use rustc_ast::util::classify;
use rustc_ast::util::parser::{AssocOp, ExprPrecedence, Fixity, prec_let_scrutinee_needs_par};
@ -2392,7 +2393,8 @@ impl<'a> Parser<'a> {
}
if self.token == TokenKind::Semi
&& matches!(self.token_cursor.stack.last(), Some((.., Delimiter::Parenthesis)))
&& let Some(last) = self.token_cursor.stack.last()
&& let Some(TokenTree::Delimited(_, _, Delimiter::Parenthesis, _)) = last.curr()
&& self.may_recover()
{
// It is likely that the closure body is a block but where the