Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve the "must use" lint for Future to suggest await #60797

Closed
nikomatsakis opened this issue May 13, 2019 · 7 comments
Closed

improve the "must use" lint for Future to suggest await #60797

nikomatsakis opened this issue May 13, 2019 · 7 comments

Comments

@nikomatsakis
Copy link
Contributor

@nikomatsakis nikomatsakis commented May 13, 2019

The following code gives a "must use" warning (which is awesome!), but the warning is not as clear as it could be:

#![feature(async_await)]
#![allow(dead_code)]

async fn foo() {
    bar();
}

async fn bar() {
}

fn main() { }

This results in:

warning: unused implementer of `std::future::Future` that must be used
 --> src/main.rs:5:5
  |
5 |     bar();
  |     ^^^^^^
  |
  = note: #[warn(unused_must_use)] on by default
  = note: futures do nothing unless polled

it should probably say "futures do nothing unless you await them" or something. Most people won't know what 'polled' is all about, I think.

@Centril
Copy link
Contributor

@Centril Centril commented May 13, 2019

The current note originates from:

#[must_use = "futures do nothing unless polled"]

To change it, simply edit that.

@Schultzer
Copy link
Contributor

@Schultzer Schultzer commented May 13, 2019

What about #[must_use = "futures stays idle unless you await them"] ?

@aesedepece
Copy link

@aesedepece aesedepece commented May 13, 2019

What about #[must_use = "futures stays idle unless you await them"] ?

In any case, #[must_use = "futures stay idle unless you await them"]. Just a typo 😉

I would actually expect something in the line of:

#[must_use = "a future does nothing unless you await or poll it. Did you miss using the `await!` macro on it?"]

Btw, I'd love to work on this issue and provide a PR. I'm really looking forward to help Rust just as much as it has helped me thus far!

@Centril
Copy link
Contributor

@Centril Centril commented May 13, 2019

We may want to work in the fact that you can use my_future.await somehow.
Other than that, #[must_use = "futures stay idle unless you await them"] sounds pretty good.

@aesedepece
Copy link

@aesedepece aesedepece commented May 13, 2019

@Centril what trait does provide my_future.await? 😲

@Centril
Copy link
Contributor

@Centril Centril commented May 13, 2019

@aesedepece my_future.await is equivalent to await!(my_future) and is likely to replace it eventually. See https://boats.gitlab.io/blog/post/await-decision/.

I think for now #[must_use = "futures stay idle unless you await them"] might be good enough and we could tweak later.

@aesedepece
Copy link

@aesedepece aesedepece commented May 13, 2019

Schultzer added a commit to Schultzer/rust that referenced this issue May 13, 2019
This fixes rust-lang#60797
Schultzer added a commit to Schultzer/rust that referenced this issue May 13, 2019
Centril added a commit to Centril/rust that referenced this issue May 14, 2019
…r-future, r=Centril

Improve the "must use" lint for `Future`

Fixes rust-lang#60797
@bors bors closed this in #60808 May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants