Skip to content

Commit 649d0a9

Browse files
authored
Rollup merge of #114237 - bvanjoi:fix-114219, r=cjgillot
parser: more friendly hints for handling `async move` in the 2015 edition Fixes #114219 An error is emitted when encountering an async move block in the 2015 edition. Another appropriate location to raise an error is after executing [let path = this.parse_path(PathStyle::Expr)?](https://github.com/rust-lang/rust/blob/master/compiler/rustc_parse/src/parser/stmt.rs#L152), but it seems somewhat premature to invoke `create_err` at that stage.
2 parents 7518ae5 + 8e32dad commit 649d0a9

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

Diff for: compiler/rustc_parse/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ parse_async_block_in_2015 = `async` blocks are only allowed in Rust 2018 or late
2323
parse_async_fn_in_2015 = `async fn` is not permitted in Rust 2015
2424
.label = to use `async fn`, switch to Rust 2018 or later
2525
26+
parse_async_move_block_in_2015 = `async move` blocks are only allowed in Rust 2018 or later
27+
2628
parse_async_move_order_incorrect = the order of `move` and `async` is incorrect
2729
.suggestion = try switching the order
2830

Diff for: compiler/rustc_parse/src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,13 @@ pub(crate) struct AsyncBlockIn2015 {
14341434
pub span: Span,
14351435
}
14361436

1437+
#[derive(Diagnostic)]
1438+
#[diag(parse_async_move_block_in_2015)]
1439+
pub(crate) struct AsyncMoveBlockIn2015 {
1440+
#[primary_span]
1441+
pub span: Span,
1442+
}
1443+
14371444
#[derive(Diagnostic)]
14381445
#[diag(parse_self_argument_pointer)]
14391446
pub(crate) struct SelfArgumentPointer {

Diff for: compiler/rustc_parse/src/parser/diagnostics.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ use super::{
44
TokenExpectType, TokenType,
55
};
66
use crate::errors::{
7-
AmbiguousPlus, AttributeOnParamType, BadQPathStage2, BadTypePlus, BadTypePlusSub, ColonAsSemi,
8-
ComparisonOperatorsCannotBeChained, ComparisonOperatorsCannotBeChainedSugg,
9-
ConstGenericWithoutBraces, ConstGenericWithoutBracesSugg, DocCommentDoesNotDocumentAnything,
10-
DocCommentOnParamType, DoubleColonInBound, ExpectedIdentifier, ExpectedSemi, ExpectedSemiSugg,
7+
AmbiguousPlus, AsyncMoveBlockIn2015, AttributeOnParamType, BadQPathStage2, BadTypePlus,
8+
BadTypePlusSub, ColonAsSemi, ComparisonOperatorsCannotBeChained,
9+
ComparisonOperatorsCannotBeChainedSugg, ConstGenericWithoutBraces,
10+
ConstGenericWithoutBracesSugg, DocCommentDoesNotDocumentAnything, DocCommentOnParamType,
11+
DoubleColonInBound, ExpectedIdentifier, ExpectedSemi, ExpectedSemiSugg,
1112
GenericParamsWithoutAngleBrackets, GenericParamsWithoutAngleBracketsSugg,
1213
HelpIdentifierStartsWithNumber, InInTypo, IncorrectAwait, IncorrectSemicolon,
1314
IncorrectUseOfAwait, ParenthesesInForHead, ParenthesesInForHeadSugg,
@@ -573,6 +574,12 @@ impl<'a> Parser<'a> {
573574
return Err(self.sess.create_err(UseEqInstead { span: self.token.span }));
574575
}
575576

577+
if self.token.is_keyword(kw::Move) && self.prev_token.is_keyword(kw::Async) {
578+
// The 2015 edition is in use because parsing of `async move` has failed.
579+
let span = self.prev_token.span.to(self.token.span);
580+
return Err(self.sess.create_err(AsyncMoveBlockIn2015 { span }));
581+
}
582+
576583
let expect = tokens_to_string(&expected);
577584
let actual = super::token_descr(&self.token);
578585
let (msg_exp, (label_sp, label_exp)) = if expected.len() > 1 {

Diff for: tests/ui/parser/issues/issue-114219.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
async move {};
3+
//~^ ERROR `async move` blocks are only allowed in Rust 2018 or later
4+
}

Diff for: tests/ui/parser/issues/issue-114219.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: `async move` blocks are only allowed in Rust 2018 or later
2+
--> $DIR/issue-114219.rs:2:5
3+
|
4+
LL | async move {};
5+
| ^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)