Code review feedback

Add a note about `IntoFuture` in error messages where T is not a future.

Change await-into-future.rs to be a run-pass test.
This commit is contained in:
Eric Holk 2021-12-02 11:36:48 -08:00
parent db80c07590
commit 0cb769347d
5 changed files with 14 additions and 5 deletions

View File

@ -28,7 +28,11 @@ use crate::task::{Context, Poll};
#[must_use = "futures do nothing unless you `.await` or poll them"]
#[stable(feature = "futures_api", since = "1.36.0")]
#[lang = "future_trait"]
#[rustc_on_unimplemented(label = "`{Self}` is not a future", message = "`{Self}` is not a future")]
#[rustc_on_unimplemented(
label = "`{Self}` is not a future",
message = "`{Self}` is not a future",
note = "{Self} must be a future or must implement `IntoFuture` to be awaited"
)]
pub trait Future {
/// The type of value produced on completion.
#[stable(feature = "futures_api", since = "1.36.0")]

View File

@ -5,6 +5,7 @@ LL | fn get_future() -> impl Future<Output = ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not a future
|
= help: the trait `Future` is not implemented for `()`
= note: () must be a future or must implement `IntoFuture` to be awaited
error[E0698]: type inside `async fn` body must be known in this context
--> $DIR/async-error-span.rs:13:9

View File

@ -1,9 +1,9 @@
// check-pass
// run-pass
// aux-build: issue-72470-lib.rs
// edition:2021
#![feature(into_future)]
extern crate issue_72470_lib;
use std::{future::{Future, IntoFuture}, pin::Pin};
struct AwaitMe;
@ -25,4 +25,6 @@ async fn run() {
assert_eq!(AwaitMe.await, 41);
}
fn main() {}
fn main() {
issue_72470_lib::run(run());
}

View File

@ -25,6 +25,7 @@ LL | [1; ().await];
| ^^^^^^^^ `()` is not a future
|
= help: the trait `Future` is not implemented for `()`
= note: () must be a future or must implement `IntoFuture` to be awaited
= note: required because of the requirements on the impl of `IntoFuture` for `()`
error: aborting due to 4 previous errors

View File

@ -34,6 +34,7 @@ LL | (|_| 2333).await;
| ^^^^^^^^^^^^^^^^ `[closure@$DIR/issue-62009-1.rs:12:5: 12:15]` is not a future
|
= help: the trait `Future` is not implemented for `[closure@$DIR/issue-62009-1.rs:12:5: 12:15]`
= note: [closure@$DIR/issue-62009-1.rs:12:5: 12:15] must be a future or must implement `IntoFuture` to be awaited
= note: required because of the requirements on the impl of `IntoFuture` for `[closure@$DIR/issue-62009-1.rs:12:5: 12:15]`
error: aborting due to 4 previous errors