Merge pull request #64019 from jckarter/se-0366-consume-final-spelling

Implement `consume x` operator with the accepted SE-0366 syntax.
This commit is contained in:
Joe Groff
2023-03-02 07:23:17 -08:00
committed by GitHub
24 changed files with 506 additions and 420 deletions

View File

@@ -406,10 +406,27 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
return sub;
}
if (Tok.isContextualKeyword("consume")
&& peekToken().isAny(tok::identifier, tok::kw_self)
&& !peekToken().isAtStartOfLine()) {
Tok.setKind(tok::contextual_keyword);
SourceLoc consumeLoc = consumeToken();
ParserResult<Expr> sub =
parseExprSequenceElement(diag::expected_expr_after_move, isExprBasic);
if (!sub.hasCodeCompletion() && !sub.isNull()) {
sub = makeParserResult(new (Context) MoveExpr(consumeLoc, sub.get()));
}
return sub;
}
if (Context.LangOpts.hasFeature(Feature::MoveOnly)) {
if (Tok.isContextualKeyword("_move")) {
Tok.setKind(tok::contextual_keyword);
SourceLoc awaitLoc = consumeToken();
diagnose(Tok, diag::move_consume_final_spelling)
.fixItReplace(awaitLoc, "consume");
ParserResult<Expr> sub =
parseExprSequenceElement(diag::expected_expr_after_move, isExprBasic);
if (!sub.hasCodeCompletion() && !sub.isNull()) {