Give a better error message on async use in edition 2015

This commit is contained in:
Santiago Pastorino 2025-02-21 17:24:46 -03:00
parent 2f48fcec63
commit 4e6407ab94
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
5 changed files with 38 additions and 8 deletions

View file

@ -31,11 +31,11 @@ use super::{
SeqSep, TokenType,
};
use crate::errors::{
AddParen, AmbiguousPlus, AsyncMoveBlockIn2015, AttributeOnParamType, AwaitSuggestion,
BadQPathStage2, BadTypePlus, BadTypePlusSub, ColonAsSemi, ComparisonOperatorsCannotBeChained,
ComparisonOperatorsCannotBeChainedSugg, ConstGenericWithoutBraces,
ConstGenericWithoutBracesSugg, DocCommentDoesNotDocumentAnything, DocCommentOnParamType,
DoubleColonInBound, ExpectedIdentifier, ExpectedSemi, ExpectedSemiSugg,
AddParen, AmbiguousPlus, AsyncMoveBlockIn2015, AsyncUseBlockIn2015, AttributeOnParamType,
AwaitSuggestion, BadQPathStage2, BadTypePlus, BadTypePlusSub, ColonAsSemi,
ComparisonOperatorsCannotBeChained, ComparisonOperatorsCannotBeChainedSugg,
ConstGenericWithoutBraces, ConstGenericWithoutBracesSugg, DocCommentDoesNotDocumentAnything,
DocCommentOnParamType, DoubleColonInBound, ExpectedIdentifier, ExpectedSemi, ExpectedSemiSugg,
GenericParamsWithoutAngleBrackets, GenericParamsWithoutAngleBracketsSugg,
HelpIdentifierStartsWithNumber, HelpUseLatestEdition, InInTypo, IncorrectAwait,
IncorrectSemicolon, IncorrectUseOfAwait, IncorrectUseOfUse, PatternMethodParamWithoutBody,
@ -572,10 +572,17 @@ impl<'a> Parser<'a> {
return Err(self.dcx().create_err(UseEqInstead { span: self.token.span }));
}
if self.token.is_keyword(kw::Move) && self.prev_token.is_keyword(kw::Async) {
// The 2015 edition is in use because parsing of `async move` has failed.
if (self.token.is_keyword(kw::Move) || self.token.is_keyword(kw::Use))
&& self.prev_token.is_keyword(kw::Async)
{
// The 2015 edition is in use because parsing of `async move` or `async use` has failed.
let span = self.prev_token.span.to(self.token.span);
return Err(self.dcx().create_err(AsyncMoveBlockIn2015 { span }));
if self.token.is_keyword(kw::Move) {
return Err(self.dcx().create_err(AsyncMoveBlockIn2015 { span }));
} else {
// kw::Use
return Err(self.dcx().create_err(AsyncUseBlockIn2015 { span }));
}
}
let expect = tokens_to_string(&expected);