未验证 提交 83756d97 编写于 作者: M Matthias Krüger 提交者: GitHub

Rollup merge of #114584 - darklyspaced:master, r=cjgillot

E0277 nolonger points at phantom `.await`

fixes #113203
...@@ -1717,13 +1717,7 @@ pub(super) fn recover_incorrect_await_syntax( ...@@ -1717,13 +1717,7 @@ pub(super) fn recover_incorrect_await_syntax(
self.recover_await_prefix(await_sp)? self.recover_await_prefix(await_sp)?
}; };
let sp = self.error_on_incorrect_await(lo, hi, &expr, is_question); let sp = self.error_on_incorrect_await(lo, hi, &expr, is_question);
let kind = match expr.kind { let expr = self.mk_expr(lo.to(sp), ExprKind::Err);
// Avoid knock-down errors as we don't know whether to interpret this as `foo().await?`
// or `foo()?.await` (the very reason we went with postfix syntax 😅).
ExprKind::Try(_) => ExprKind::Err,
_ => ExprKind::Await(expr, await_sp),
};
let expr = self.mk_expr(lo.to(sp), kind);
self.maybe_recover_from_bad_qpath(expr) self.maybe_recover_from_bad_qpath(expr)
} }
......
...@@ -49,13 +49,11 @@ async fn foo8() -> Result<(), ()> { ...@@ -49,13 +49,11 @@ async fn foo8() -> Result<(), ()> {
Ok(()) Ok(())
} }
fn foo9() -> Result<(), ()> { fn foo9() -> Result<(), ()> {
let _ = await bar(); //~ ERROR `await` is only allowed inside `async` functions and blocks let _ = await bar(); //~ ERROR incorrect use of `await`
//~^ ERROR incorrect use of `await`
Ok(()) Ok(())
} }
fn foo10() -> Result<(), ()> { fn foo10() -> Result<(), ()> {
let _ = await? bar(); //~ ERROR `await` is only allowed inside `async` functions and blocks let _ = await? bar(); //~ ERROR incorrect use of `await`
//~^ ERROR incorrect use of `await`
Ok(()) Ok(())
} }
fn foo11() -> Result<(), ()> { fn foo11() -> Result<(), ()> {
...@@ -63,8 +61,7 @@ fn foo11() -> Result<(), ()> { ...@@ -63,8 +61,7 @@ fn foo11() -> Result<(), ()> {
Ok(()) Ok(())
} }
fn foo12() -> Result<(), ()> { fn foo12() -> Result<(), ()> {
let _ = (await bar())?; //~ ERROR `await` is only allowed inside `async` functions and blocks let _ = (await bar())?; //~ ERROR incorrect use of `await`
//~^ ERROR incorrect use of `await`
Ok(()) Ok(())
} }
fn foo13() -> Result<(), ()> { fn foo13() -> Result<(), ()> {
...@@ -111,7 +108,6 @@ async fn foo27() -> Result<(), ()> { ...@@ -111,7 +108,6 @@ async fn foo27() -> Result<(), ()> {
fn foo28() -> Result<(), ()> { fn foo28() -> Result<(), ()> {
fn foo() -> Result<(), ()> { fn foo() -> Result<(), ()> {
let _ = await!(bar())?; //~ ERROR incorrect use of `await` let _ = await!(bar())?; //~ ERROR incorrect use of `await`
//~^ ERROR `await` is only allowed inside `async` functions
Ok(()) Ok(())
} }
foo() foo()
...@@ -119,7 +115,6 @@ fn foo() -> Result<(), ()> { ...@@ -119,7 +115,6 @@ fn foo() -> Result<(), ()> {
fn foo29() -> Result<(), ()> { fn foo29() -> Result<(), ()> {
let foo = || { let foo = || {
let _ = await!(bar())?; //~ ERROR incorrect use of `await` let _ = await!(bar())?; //~ ERROR incorrect use of `await`
//~^ ERROR `await` is only allowed inside `async` functions
Ok(()) Ok(())
}; };
foo() foo()
......
...@@ -59,61 +59,61 @@ LL | let _ = await bar(); ...@@ -59,61 +59,61 @@ LL | let _ = await bar();
| ^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await` | ^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await`
error: incorrect use of `await` error: incorrect use of `await`
--> $DIR/incorrect-syntax-suggestions.rs:57:13 --> $DIR/incorrect-syntax-suggestions.rs:56:13
| |
LL | let _ = await? bar(); LL | let _ = await? bar();
| ^^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await?` | ^^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await?`
error: incorrect use of `await` error: incorrect use of `await`
--> $DIR/incorrect-syntax-suggestions.rs:62:13 --> $DIR/incorrect-syntax-suggestions.rs:60:13
| |
LL | let _ = await bar()?; LL | let _ = await bar()?;
| ^^^^^^^^^^^^ help: `await` is a postfix operation: `bar()?.await` | ^^^^^^^^^^^^ help: `await` is a postfix operation: `bar()?.await`
error: incorrect use of `await` error: incorrect use of `await`
--> $DIR/incorrect-syntax-suggestions.rs:66:14 --> $DIR/incorrect-syntax-suggestions.rs:64:14
| |
LL | let _ = (await bar())?; LL | let _ = (await bar())?;
| ^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await` | ^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await`
error: incorrect use of `await` error: incorrect use of `await`
--> $DIR/incorrect-syntax-suggestions.rs:71:24 --> $DIR/incorrect-syntax-suggestions.rs:68:24
| |
LL | let _ = bar().await(); LL | let _ = bar().await();
| ^^ help: `await` is not a method call, remove the parentheses | ^^ help: `await` is not a method call, remove the parentheses
error: incorrect use of `await` error: incorrect use of `await`
--> $DIR/incorrect-syntax-suggestions.rs:76:24 --> $DIR/incorrect-syntax-suggestions.rs:73:24
| |
LL | let _ = bar().await()?; LL | let _ = bar().await()?;
| ^^ help: `await` is not a method call, remove the parentheses | ^^ help: `await` is not a method call, remove the parentheses
error: incorrect use of `await` error: incorrect use of `await`
--> $DIR/incorrect-syntax-suggestions.rs:104:13 --> $DIR/incorrect-syntax-suggestions.rs:101:13
| |
LL | let _ = await!(bar()); LL | let _ = await!(bar());
| ^^^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await` | ^^^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await`
error: incorrect use of `await` error: incorrect use of `await`
--> $DIR/incorrect-syntax-suggestions.rs:108:13 --> $DIR/incorrect-syntax-suggestions.rs:105:13
| |
LL | let _ = await!(bar())?; LL | let _ = await!(bar())?;
| ^^^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await` | ^^^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await`
error: incorrect use of `await` error: incorrect use of `await`
--> $DIR/incorrect-syntax-suggestions.rs:113:17 --> $DIR/incorrect-syntax-suggestions.rs:110:17
| |
LL | let _ = await!(bar())?; LL | let _ = await!(bar())?;
| ^^^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await` | ^^^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await`
error: incorrect use of `await` error: incorrect use of `await`
--> $DIR/incorrect-syntax-suggestions.rs:121:17 --> $DIR/incorrect-syntax-suggestions.rs:117:17
| |
LL | let _ = await!(bar())?; LL | let _ = await!(bar())?;
| ^^^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await` | ^^^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await`
error: expected expression, found `=>` error: expected expression, found `=>`
--> $DIR/incorrect-syntax-suggestions.rs:129:25 --> $DIR/incorrect-syntax-suggestions.rs:124:25
| |
LL | match await { await => () } LL | match await { await => () }
| ----- ^^ expected expression | ----- ^^ expected expression
...@@ -121,13 +121,13 @@ LL | match await { await => () } ...@@ -121,13 +121,13 @@ LL | match await { await => () }
| while parsing this incorrect await expression | while parsing this incorrect await expression
error: incorrect use of `await` error: incorrect use of `await`
--> $DIR/incorrect-syntax-suggestions.rs:129:11 --> $DIR/incorrect-syntax-suggestions.rs:124:11
| |
LL | match await { await => () } LL | match await { await => () }
| ^^^^^^^^^^^^^^^^^^^^^ help: `await` is a postfix operation: `{ await => () }.await` | ^^^^^^^^^^^^^^^^^^^^^ help: `await` is a postfix operation: `{ await => () }.await`
error: expected one of `.`, `?`, `{`, or an operator, found `}` error: expected one of `.`, `?`, `{`, or an operator, found `}`
--> $DIR/incorrect-syntax-suggestions.rs:132:1 --> $DIR/incorrect-syntax-suggestions.rs:127:1
| |
LL | match await { await => () } LL | match await { await => () }
| ----- - expected one of `.`, `?`, `{`, or an operator | ----- - expected one of `.`, `?`, `{`, or an operator
...@@ -138,31 +138,7 @@ LL | } ...@@ -138,31 +138,7 @@ LL | }
| ^ unexpected token | ^ unexpected token
error[E0728]: `await` is only allowed inside `async` functions and blocks error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/incorrect-syntax-suggestions.rs:52:13 --> $DIR/incorrect-syntax-suggestions.rs:68:19
|
LL | fn foo9() -> Result<(), ()> {
| ---- this is not `async`
LL | let _ = await bar();
| ^^^^^ only allowed inside `async` functions and blocks
error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/incorrect-syntax-suggestions.rs:57:13
|
LL | fn foo10() -> Result<(), ()> {
| ----- this is not `async`
LL | let _ = await? bar();
| ^^^^^ only allowed inside `async` functions and blocks
error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/incorrect-syntax-suggestions.rs:66:14
|
LL | fn foo12() -> Result<(), ()> {
| ----- this is not `async`
LL | let _ = (await bar())?;
| ^^^^^ only allowed inside `async` functions and blocks
error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/incorrect-syntax-suggestions.rs:71:19
| |
LL | fn foo13() -> Result<(), ()> { LL | fn foo13() -> Result<(), ()> {
| ----- this is not `async` | ----- this is not `async`
...@@ -170,7 +146,7 @@ LL | let _ = bar().await(); ...@@ -170,7 +146,7 @@ LL | let _ = bar().await();
| ^^^^^ only allowed inside `async` functions and blocks | ^^^^^ only allowed inside `async` functions and blocks
error[E0728]: `await` is only allowed inside `async` functions and blocks error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/incorrect-syntax-suggestions.rs:76:19 --> $DIR/incorrect-syntax-suggestions.rs:73:19
| |
LL | fn foo14() -> Result<(), ()> { LL | fn foo14() -> Result<(), ()> {
| ----- this is not `async` | ----- this is not `async`
...@@ -178,7 +154,7 @@ LL | let _ = bar().await()?; ...@@ -178,7 +154,7 @@ LL | let _ = bar().await()?;
| ^^^^^ only allowed inside `async` functions and blocks | ^^^^^ only allowed inside `async` functions and blocks
error[E0728]: `await` is only allowed inside `async` functions and blocks error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/incorrect-syntax-suggestions.rs:81:19 --> $DIR/incorrect-syntax-suggestions.rs:78:19
| |
LL | fn foo15() -> Result<(), ()> { LL | fn foo15() -> Result<(), ()> {
| ----- this is not `async` | ----- this is not `async`
...@@ -186,7 +162,7 @@ LL | let _ = bar().await; ...@@ -186,7 +162,7 @@ LL | let _ = bar().await;
| ^^^^^ only allowed inside `async` functions and blocks | ^^^^^ only allowed inside `async` functions and blocks
error[E0728]: `await` is only allowed inside `async` functions and blocks error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/incorrect-syntax-suggestions.rs:85:19 --> $DIR/incorrect-syntax-suggestions.rs:82:19
| |
LL | fn foo16() -> Result<(), ()> { LL | fn foo16() -> Result<(), ()> {
| ----- this is not `async` | ----- this is not `async`
...@@ -194,7 +170,7 @@ LL | let _ = bar().await?; ...@@ -194,7 +170,7 @@ LL | let _ = bar().await?;
| ^^^^^ only allowed inside `async` functions and blocks | ^^^^^ only allowed inside `async` functions and blocks
error[E0728]: `await` is only allowed inside `async` functions and blocks error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/incorrect-syntax-suggestions.rs:90:23 --> $DIR/incorrect-syntax-suggestions.rs:87:23
| |
LL | fn foo() -> Result<(), ()> { LL | fn foo() -> Result<(), ()> {
| --- this is not `async` | --- this is not `async`
...@@ -202,29 +178,13 @@ LL | let _ = bar().await?; ...@@ -202,29 +178,13 @@ LL | let _ = bar().await?;
| ^^^^^ only allowed inside `async` functions and blocks | ^^^^^ only allowed inside `async` functions and blocks
error[E0728]: `await` is only allowed inside `async` functions and blocks error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/incorrect-syntax-suggestions.rs:97:23 --> $DIR/incorrect-syntax-suggestions.rs:94:23
| |
LL | let foo = || { LL | let foo = || {
| -- this is not `async` | -- this is not `async`
LL | let _ = bar().await?; LL | let _ = bar().await?;
| ^^^^^ only allowed inside `async` functions and blocks | ^^^^^ only allowed inside `async` functions and blocks
error[E0728]: `await` is only allowed inside `async` functions and blocks error: aborting due to 28 previous errors
--> $DIR/incorrect-syntax-suggestions.rs:113:17
|
LL | fn foo() -> Result<(), ()> {
| --- this is not `async`
LL | let _ = await!(bar())?;
| ^^^^^ only allowed inside `async` functions and blocks
error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/incorrect-syntax-suggestions.rs:121:17
|
LL | let foo = || {
| -- this is not `async`
LL | let _ = await!(bar())?;
| ^^^^^ only allowed inside `async` functions and blocks
error: aborting due to 33 previous errors
For more information about this error, try `rustc --explain E0728`. For more information about this error, try `rustc --explain E0728`.
// Checks what happens when we attempt to use the await keyword as a prefix. Span
// incorrectly emitted an `.await` in E0277 which does not exist
// edition:2018
fn main() {
await {}()
//~^ ERROR incorrect use of `await`
}
error: incorrect use of `await`
--> $DIR/issue-113203.rs:5:5
|
LL | await {}()
| ^^^^^^^^ help: `await` is a postfix operation: `{}.await`
error: aborting due to previous error
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册