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

warn on must_use use on async fn's #89610

Merged
merged 2 commits into from
Nov 17, 2021
Merged

Conversation

guswynn
Copy link
Contributor

@guswynn guswynn commented Oct 6, 2021

As referenced in #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)

@rust-highfive
Copy link
Collaborator

r? @wesleywiser

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 6, 2021
@wesleywiser wesleywiser added the AsyncAwait-Polish Async-await issues that are part of the "polish" area label Oct 13, 2021
@wesleywiser
Copy link
Member

wesleywiser commented Oct 13, 2021

cc @eholk since this is an async-polish item

Before r+ing, I need to double check if we need to get the ok from the lang team before adding new warnings

@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 14, 2021
@eholk
Copy link
Contributor

eholk commented Oct 18, 2021

Looks good to me!

@wesleywiser wesleywiser added I-nominated T-lang Relevant to the language team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 19, 2021
@wesleywiser
Copy link
Member

Nominating for lang team discussion. This PR adds a new warning that detects #[must_use] attributes applied to async fns which currently does nothing.

warning: `must_use` attribute on `async` functions applies to the anonymous Future returned by the function, not the value within.
  --> $DIR/unused-async.rs:5:1
   |
LL |   #[must_use]
   |   ^^^^^^^^^^^
LL |
LL | / async fn test() -> i32 {
LL | |     1
LL | | }
   | |_- this attribute does nothing, the Futures returned by async functions are already `must_use`

@Mark-Simulacrum
Copy link
Member

I suspect this might just be an oversight in this PR, but it seems like this should be an unused_attributes lint, not an unconditional warning (and a custom message is still fine).

If so, then I suspect it need not receive T-lang approval... though that is a little murky these days :)

@Mark-Simulacrum
Copy link
Member

T-lang discussed this in today's meeting and agreed that this can move ahead. We may eventually want to make the must_use have behavior related to return of the .await'ing the resulting future, but that's not happening immediately (if ever), so we can move ahead here in the meantime.

We briefly discussed my concern around unused_attributes and generally felt positive about its use here, I think.

@wesleywiser wesleywiser added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 25, 2021
@guswynn
Copy link
Contributor Author

guswynn commented Oct 29, 2021

@wesleywiser what review is outstanding?

@wesleywiser
Copy link
Member

@guswynn I believe this is still waiting on Mark's feedback to be addressed:

it seems like this should be an unused_attributes lint, not an unconditional warning (and a custom message is still fine).

@guswynn
Copy link
Contributor Author

guswynn commented Nov 8, 2021

@wesleywiser sorry about the delay, was on a break, this should now be ready!

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@wesleywiser wesleywiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks @guswynn!

@wesleywiser
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Nov 13, 2021

📌 Commit 958de5a has been approved by wesleywiser

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 13, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 13, 2021
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)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 15, 2021
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)
Co-authored-by: Yuki Okushi <jtitor@2k36.org>
@wesleywiser
Copy link
Member

Blessed tests.

@bors r+

@bors
Copy link
Contributor

bors commented Nov 16, 2021

📌 Commit 83ce771 has been approved by wesleywiser

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 16, 2021
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)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 16, 2021
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)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 16, 2021
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)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 17, 2021
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)
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 17, 2021
…askrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#89610 (warn on must_use use on async fn's)
 - rust-lang#90667 (Improve diagnostics when a static lifetime is expected)
 - rust-lang#90687 (Permit const panics in stable const contexts in stdlib)
 - rust-lang#90772 (Add Vec::retain_mut)
 - rust-lang#90861 (Print escaped string if char literal has multiple characters, but only one printable character)
 - rust-lang#90884 (Fix span for non-satisfied trivial trait bounds)
 - rust-lang#90900 (Remove workaround for the forward progress handling in LLVM)
 - rust-lang#90901 (Improve ManuallyDrop suggestion)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0734282 into rust-lang:master Nov 17, 2021
@rustbot rustbot added this to the 1.58.0 milestone Nov 17, 2021
@guswynn
Copy link
Contributor Author

guswynn commented Nov 23, 2021

@wesleywiser you are a legend for blessing those tests, sorry this fell off my radar!

@wesleywiser
Copy link
Member

@guswynn Thanks for working on it!! 🎉

naturallymitchell pushed a commit to naturallymitchell/fuchsia-storage that referenced this pull request Jun 10, 2022
The Future type that an async function implicitly returns is already
implicitly marked as must_use, and additional must_use annotations on
async functions are, therefore, redundant. These unneeded annotations
generate a warning, which is an error in our build, with this change to
the rust compiler rust-lang/rust#89610

Bug: 88999
Change-Id: I84685942c30eeaf98ad9597285d289d5bcbc12d3
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/608581
Reviewed-by: Abdulla Kamar <abdulla@google.com>
Fuchsia-Auto-Submit: Adrian Danis <adanis@google.com>
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AsyncAwait-Polish Async-await issues that are part of the "polish" area S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants