Fix use closure parsing error message

This commit is contained in:
Santiago Pastorino 2025-02-11 11:13:33 -03:00
parent 7c17bf8e82
commit 292aa87049
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
3 changed files with 20 additions and 15 deletions

View file

@ -209,9 +209,7 @@ impl<'a> Parser<'a> {
let check_pub = def == &Defaultness::Final;
let mut def_ = || mem::replace(def, Defaultness::Final);
let info = if !self.look_ahead(1, |t| [token::OrOr, token::Or].contains(&t.kind))
&& self.eat_keyword_case(exp!(Use), case)
{
let info = if !self.is_use_closure() && self.eat_keyword_case(exp!(Use), case) {
self.parse_use_item()?
} else if self.check_fn_front_matter(check_pub, case) {
// FUNCTION ITEM
@ -1279,6 +1277,21 @@ impl<'a> Parser<'a> {
None
}
fn is_use_closure(&self) -> bool {
if self.token.is_keyword(kw::Use) {
// Check if this could be a closure.
self.look_ahead(1, |token| {
// Move or Async here would be an error but still we're parsing a closure
let dist =
if token.is_keyword(kw::Move) || token.is_keyword(kw::Async) { 2 } else { 1 };
self.look_ahead(dist, |token| matches!(token.kind, token::Or | token::OrOr))
})
} else {
false
}
}
fn is_unsafe_foreign_mod(&self) -> bool {
self.token.is_keyword(kw::Unsafe)
&& self.is_keyword_ahead(1, &[kw::Extern])