parser: more friendly hints for handling async move
in the 2015 edition
This commit is contained in:
parent
d9feb02e8d
commit
8e32dade71
@ -23,6 +23,8 @@ parse_async_block_in_2015 = `async` blocks are only allowed in Rust 2018 or late
|
|||||||
parse_async_fn_in_2015 = `async fn` is not permitted in Rust 2015
|
parse_async_fn_in_2015 = `async fn` is not permitted in Rust 2015
|
||||||
.label = to use `async fn`, switch to Rust 2018 or later
|
.label = to use `async fn`, switch to Rust 2018 or later
|
||||||
|
|
||||||
|
parse_async_move_block_in_2015 = `async move` blocks are only allowed in Rust 2018 or later
|
||||||
|
|
||||||
parse_async_move_order_incorrect = the order of `move` and `async` is incorrect
|
parse_async_move_order_incorrect = the order of `move` and `async` is incorrect
|
||||||
.suggestion = try switching the order
|
.suggestion = try switching the order
|
||||||
|
|
||||||
|
@ -1434,6 +1434,13 @@ pub(crate) struct AsyncBlockIn2015 {
|
|||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(parse_async_move_block_in_2015)]
|
||||||
|
pub(crate) struct AsyncMoveBlockIn2015 {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(parse_self_argument_pointer)]
|
#[diag(parse_self_argument_pointer)]
|
||||||
pub(crate) struct SelfArgumentPointer {
|
pub(crate) struct SelfArgumentPointer {
|
||||||
|
@ -4,10 +4,11 @@ use super::{
|
|||||||
TokenExpectType, TokenType,
|
TokenExpectType, TokenType,
|
||||||
};
|
};
|
||||||
use crate::errors::{
|
use crate::errors::{
|
||||||
AmbiguousPlus, AttributeOnParamType, BadQPathStage2, BadTypePlus, BadTypePlusSub, ColonAsSemi,
|
AmbiguousPlus, AsyncMoveBlockIn2015, AttributeOnParamType, BadQPathStage2, BadTypePlus,
|
||||||
ComparisonOperatorsCannotBeChained, ComparisonOperatorsCannotBeChainedSugg,
|
BadTypePlusSub, ColonAsSemi, ComparisonOperatorsCannotBeChained,
|
||||||
ConstGenericWithoutBraces, ConstGenericWithoutBracesSugg, DocCommentDoesNotDocumentAnything,
|
ComparisonOperatorsCannotBeChainedSugg, ConstGenericWithoutBraces,
|
||||||
DocCommentOnParamType, DoubleColonInBound, ExpectedIdentifier, ExpectedSemi, ExpectedSemiSugg,
|
ConstGenericWithoutBracesSugg, DocCommentDoesNotDocumentAnything, DocCommentOnParamType,
|
||||||
|
DoubleColonInBound, ExpectedIdentifier, ExpectedSemi, ExpectedSemiSugg,
|
||||||
GenericParamsWithoutAngleBrackets, GenericParamsWithoutAngleBracketsSugg,
|
GenericParamsWithoutAngleBrackets, GenericParamsWithoutAngleBracketsSugg,
|
||||||
HelpIdentifierStartsWithNumber, InInTypo, IncorrectAwait, IncorrectSemicolon,
|
HelpIdentifierStartsWithNumber, InInTypo, IncorrectAwait, IncorrectSemicolon,
|
||||||
IncorrectUseOfAwait, ParenthesesInForHead, ParenthesesInForHeadSugg,
|
IncorrectUseOfAwait, ParenthesesInForHead, ParenthesesInForHeadSugg,
|
||||||
@ -573,6 +574,12 @@ impl<'a> Parser<'a> {
|
|||||||
return Err(self.sess.create_err(UseEqInstead { span: self.token.span }));
|
return Err(self.sess.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.
|
||||||
|
let span = self.prev_token.span.to(self.token.span);
|
||||||
|
return Err(self.sess.create_err(AsyncMoveBlockIn2015 { span }));
|
||||||
|
}
|
||||||
|
|
||||||
let expect = tokens_to_string(&expected);
|
let expect = tokens_to_string(&expected);
|
||||||
let actual = super::token_descr(&self.token);
|
let actual = super::token_descr(&self.token);
|
||||||
let (msg_exp, (label_sp, label_exp)) = if expected.len() > 1 {
|
let (msg_exp, (label_sp, label_exp)) = if expected.len() > 1 {
|
||||||
|
4
tests/ui/parser/issues/issue-114219.rs
Normal file
4
tests/ui/parser/issues/issue-114219.rs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
fn main() {
|
||||||
|
async move {};
|
||||||
|
//~^ ERROR `async move` blocks are only allowed in Rust 2018 or later
|
||||||
|
}
|
8
tests/ui/parser/issues/issue-114219.stderr
Normal file
8
tests/ui/parser/issues/issue-114219.stderr
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
error: `async move` blocks are only allowed in Rust 2018 or later
|
||||||
|
--> $DIR/issue-114219.rs:2:5
|
||||||
|
|
|
||||||
|
LL | async move {};
|
||||||
|
| ^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user