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

unused_async lint does not work for methods #9024

Closed
david-perez opened this issue Jun 19, 2022 · 0 comments · Fixed by #9025
Closed

unused_async lint does not work for methods #9024

david-perez opened this issue Jun 19, 2022 · 0 comments · Fixed by #9025
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@david-perez
Copy link

david-perez commented Jun 19, 2022

Summary

This program:

use async_trait::async_trait;

#[async_trait]
trait AsyncTrait {
    async fn async_baz(&self) -> &'static str;
}

struct App;

impl App {
    pub async fn method(&self) -> &'static str {
        "incorrectly not caught by clippy"
    }
}

#[async_trait]
impl AsyncTrait for App {
    async fn async_baz(&self) -> &'static str {
        "correctly not caught by clippy"
    }
}

pub async fn freestanding() -> &'static str {
    "correctly caught by clippy"
}

fn main() {
    let app = App;
    let _ = app.method();
}

Makes cargo clippy -- --deny clippy::unused_async yield:

error: unused `async` for function with no await statements
  --> src/main.rs:23:1
   |
23 | / pub async fn freestanding() -> &'static str {
24 | |     "correctly caught by clippy"
25 | | }
   | |_^
   |
   = note: requested on the command line with `-D clippy::unused-async`
   = help: consider removing the `async` from this function
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_async

error: could not compile `clippy-unused-async` due to previous error

However, I see no reason why it should not lint against method.

Lint introduced in #7225.

Version

rustc 1.61.0 (fe5b13d68 2022-05-18)
binary: rustc
commit-hash: fe5b13d681f25ee6474be29d748c65adcd91f69e
commit-date: 2022-05-18
host: x86_64-unknown-linux-gnu
release: 1.61.0
LLVM version: 14.0.0
@david-perez david-perez added the C-bug Category: Clippy is not doing the correct thing label Jun 19, 2022
@Alexendoo Alexendoo added the I-false-negative Issue: The lint should have been triggered on code, but wasn't label Jun 20, 2022
@bors bors closed this as completed in 97d4513 Jun 20, 2022
bors bot added a commit to maidsafe/temp_safe_network that referenced this issue Jun 27, 2022
1276: chore(misc): remove unused asyncs (clippy) r=joshuef a=b-zee

Upon removing async keywords from
sn_interface/src/network_knowledge/mod.rs a lot of removal propagated up
and removed most of it with help of Clippy. Clippy does not yet detect
unnecessary async in methods
(rust-lang/rust-clippy#9024), but will soon.

With the help of a new Clippy lint:
cargo clippy --all-targets --all-features -- -W clippy::unused_async
And automatically fixing code with:
cargo fix --broken-code --allow-dirty --all-targets --all-features

Results mostly from the single thread work of `@joshuef` in #1253 (and
ongoing efforts).

<!--
Thanks for contributing to the project! We recommend you check out our "Guide to contributing" page if you haven't already: https://github.com/maidsafe/QA/blob/master/CONTRIBUTING.md

Write your comment below this line: -->


Co-authored-by: Benno Zeeman <[email protected]>
joshuef pushed a commit to maidsafe/temp_safe_network that referenced this issue Jun 28, 2022
Upon removing async keywords from
sn_interface/src/network_knowledge/mod.rs a lot of removal propagated up
and removed most of it with help of Clippy. Clippy does not yet detect
unnecessary async in methods
(rust-lang/rust-clippy#9024), but will soon.

With the help of a new Clippy lint:
cargo clippy --all-targets --all-features -- -W clippy::unused_async
And automatically fixing code with:
cargo fix --broken-code --allow-dirty --all-targets --all-features

Results mostly from the single thread work of @joshuef in #1253 (and
ongoing efforts).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants