Rollup merge of #71948 - csmoe:issue-61076, r=oli-obk
Suggest to await future before ? operator Closes https://github.com/rust-lang/rust/issues/71811 cc #61076
This commit is contained in:
commit
badcf267df
13 changed files with 246 additions and 37 deletions
|
|
@ -237,7 +237,10 @@ error[E0277]: the `?` operator can only be applied to values that implement `std
|
|||
--> $DIR/incorrect-syntax-suggestions.rs:16:19
|
||||
|
|
||||
LL | let _ = await bar()?;
|
||||
| ^^^^^^ the `?` operator cannot be applied to type `impl std::future::Future`
|
||||
| ^^^^^^
|
||||
| |
|
||||
| the `?` operator cannot be applied to type `impl std::future::Future`
|
||||
| help: consider using `.await` here: `bar().await?`
|
||||
|
|
||||
= help: the trait `std::ops::Try` is not implemented for `impl std::future::Future`
|
||||
= note: required by `std::ops::Try::into_result`
|
||||
|
|
|
|||
32
src/test/ui/async-await/issue-61076.rs
Normal file
32
src/test/ui/async-await/issue-61076.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// edition:2018
|
||||
|
||||
use core::future::Future;
|
||||
use core::pin::Pin;
|
||||
use core::task::{Context, Poll};
|
||||
|
||||
struct T;
|
||||
|
||||
impl Future for T {
|
||||
type Output = Result<(), ()>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
Poll::Pending
|
||||
}
|
||||
}
|
||||
|
||||
async fn foo() -> Result<(), ()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn bar() -> Result<(), ()> {
|
||||
foo()?; //~ ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn baz() -> Result<(), ()> {
|
||||
let t = T;
|
||||
t?; //~ ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
27
src/test/ui/async-await/issue-61076.stderr
Normal file
27
src/test/ui/async-await/issue-61076.stderr
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try`
|
||||
--> $DIR/issue-61076.rs:22:5
|
||||
|
|
||||
LL | foo()?;
|
||||
| ^^^^^^
|
||||
| |
|
||||
| the `?` operator cannot be applied to type `impl std::future::Future`
|
||||
| help: consider using `.await` here: `foo().await?`
|
||||
|
|
||||
= help: the trait `std::ops::Try` is not implemented for `impl std::future::Future`
|
||||
= note: required by `std::ops::Try::into_result`
|
||||
|
||||
error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try`
|
||||
--> $DIR/issue-61076.rs:28:5
|
||||
|
|
||||
LL | t?;
|
||||
| ^^
|
||||
| |
|
||||
| the `?` operator cannot be applied to type `T`
|
||||
| help: consider using `.await` here: `t.await?`
|
||||
|
|
||||
= help: the trait `std::ops::Try` is not implemented for `T`
|
||||
= note: required by `std::ops::Try::into_result`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -7,7 +7,8 @@ async fn an_async_block() -> u32 {
|
|||
let x: Option<u32> = None;
|
||||
x?; //~ ERROR the `?` operator
|
||||
22
|
||||
}.await
|
||||
}
|
||||
.await
|
||||
}
|
||||
|
||||
async fn async_closure_containing_fn() -> u32 {
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ LL | | let x: Option<u32> = None;
|
|||
LL | | x?;
|
||||
| | ^^ cannot use the `?` operator in an async block that returns `{integer}`
|
||||
LL | | 22
|
||||
LL | | }.await
|
||||
LL | | }
|
||||
| |_____- this function should return `Result` or `Option` to accept `?`
|
||||
|
|
||||
= help: the trait `std::ops::Try` is not implemented for `{integer}`
|
||||
= note: required by `std::ops::Try::from_error`
|
||||
|
||||
error[E0277]: the `?` operator can only be used in an async closure that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
|
||||
--> $DIR/try-on-option-in-async.rs:16:9
|
||||
--> $DIR/try-on-option-in-async.rs:17:9
|
||||
|
|
||||
LL | let async_closure = async || {
|
||||
| __________________________________-
|
||||
|
|
@ -29,7 +29,7 @@ LL | | };
|
|||
= note: required by `std::ops::Try::from_error`
|
||||
|
||||
error[E0277]: the `?` operator can only be used in an async function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
|
||||
--> $DIR/try-on-option-in-async.rs:25:5
|
||||
--> $DIR/try-on-option-in-async.rs:26:5
|
||||
|
|
||||
LL | async fn an_async_function() -> u32 {
|
||||
| _____________________________________-
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue