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 · Fixed by #60808
Closed

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

nikomatsakis opened this issue May 13, 2019 · 7 comments · Fixed by #60808
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nikomatsakis
Copy link
Contributor

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.

@nikomatsakis nikomatsakis added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-async-await Area: Async & Await labels May 13, 2019
@Centril Centril added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label May 13, 2019
@Centril
Copy link
Contributor

Centril commented May 13, 2019

The current note originates from:

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

To change it, simply edit that.

@Centril Centril added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label May 13, 2019
@Schultzer
Copy link
Contributor

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

@aesedepece
Copy link

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 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

@Centril what trait does provide my_future.await? 😲

@Centril
Copy link
Contributor

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 commented May 13, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
4 participants