-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
#[must_use] on async fns works on returned Future
instead of the awaited value
#78149
Comments
I think this is indeed a bug, or at the very least unexpected behavior. It might be challenging to fix, since I don't know of a way to express the desired desugaring. |
I agree that this will be challenging. The first problem as you said is that, in the desugaring, the Second problem then would be that the lint would have to have the idea of a "must use future" (let's call it), and it would have to track when that future is awaited and figure out that the resulting value is itself I'm pondering if there is a generalization that might make this easier and less special case, not clear. |
In the short term we could make a lint to warn people who use the attribute on async fns that it won't do anything. |
Assigning |
A hacky workaround for this is to wrap the return type inside a
and the compiler will emit warnings for the unused result. |
@rustbot claim At least "In the short term we could make a lint to warn people who use the attribute on async fns that it won't do anything." part |
@rustbot label AsyncAwait-Polish |
Error: Label AsyncAwait-Polish can only be set by Rust team members Please let |
@rustbot label AsyncAwait-Polish |
warn on must_use use on async fn's As referenced in rust-lang#78149 This only works on `async` fn's for now, I can also look into if I can get `Box<dyn Future>` and `impl Future` working at this level (hir)
warn on must_use use on async fn's As referenced in rust-lang#78149 This only works on `async` fn's for now, I can also look into if I can get `Box<dyn Future>` and `impl Future` working at this level (hir)
warn on must_use use on async fn's As referenced in rust-lang#78149 This only works on `async` fn's for now, I can also look into if I can get `Box<dyn Future>` and `impl Future` working at this level (hir)
warn on must_use use on async fn's As referenced in rust-lang#78149 This only works on `async` fn's for now, I can also look into if I can get `Box<dyn Future>` and `impl Future` working at this level (hir)
warn on must_use use on async fn's As referenced in rust-lang#78149 This only works on `async` fn's for now, I can also look into if I can get `Box<dyn Future>` and `impl Future` working at this level (hir)
warn on must_use use on async fn's As referenced in rust-lang#78149 This only works on `async` fn's for now, I can also look into if I can get `Box<dyn Future>` and `impl Future` working at this level (hir)
warn on must_use use on async fn's As referenced in rust-lang#78149 This only works on `async` fn's for now, I can also look into if I can get `Box<dyn Future>` and `impl Future` working at this level (hir)
A similar issue arises with Another way to look at this is that both |
Unfortunately these don't work as they're applied to the future and not the value returned by the future. rust-lang/rust#78149
… r=tmandry Consider `#[must_use]` annotation on `async fn` as also affecting the `Future::Output` No longer lint against `#[must_use] async fn foo()`. When encountering a statement that awaits on a `Future`, check if the `Future`'s parent item is annotated with `#[must_use]` and emit a lint if so. This effectively makes `must_use` an annotation on the `Future::Output` instead of only the `Future` itself. Fix rust-lang#78149.
… r=tmandry Consider `#[must_use]` annotation on `async fn` as also affecting the `Future::Output` No longer lint against `#[must_use] async fn foo()`. When encountering a statement that awaits on a `Future`, check if the `Future`'s parent item is annotated with `#[must_use]` and emit a lint if so. This effectively makes `must_use` an annotation on the `Future::Output` instead of only the `Future` itself. Fix rust-lang#78149.
… r=tmandry Consider `#[must_use]` annotation on `async fn` as also affecting the `Future::Output` No longer lint against `#[must_use] async fn foo()`. When encountering a statement that awaits on a `Future`, check if the `Future`'s parent item is annotated with `#[must_use]` and emit a lint if so. This effectively makes `must_use` an annotation on the `Future::Output` instead of only the `Future` itself. Fix rust-lang#78149.
… r=tmandry Consider `#[must_use]` annotation on `async fn` as also affecting the `Future::Output` No longer lint against `#[must_use] async fn foo()`. When encountering a statement that awaits on a `Future`, check if the `Future`'s parent item is annotated with `#[must_use]` and emit a lint if so. This effectively makes `must_use` an annotation on the `Future::Output` instead of only the `Future` itself. Fix rust-lang#78149.
I tried this code:
I expected the compiler to warn about the unused return value in
without_warning()
, but the compiler emitted two warnings inwith_warnings()
:Playground (tried using nightly 2020-10-18 b1496c6)
As the real return values of
async fn
s are actuallyimpl Future
s, you may consider this as the expected behavior (I don't agree, andimpl Future
s are already#[must_use]
). If that is the case, there should be a way to make the compiler warn on unused.await
ed values (when type of the.await
ed value is not#[must_use]
).@rustbot modify labels: A-async-await A-lint -A-diagnostics
The text was updated successfully, but these errors were encountered: