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

New lint: unused_async #7225

Merged
merged 3 commits into from
May 17, 2021
Merged

New lint: unused_async #7225

merged 3 commits into from
May 17, 2021

Conversation

snowsignal
Copy link

changelog: Adds a lint, unused_async, which checks for async functions with no await statements

unused_async is a lint that reduces code smell and overhead by encouraging async functions to be refactored into synchronous functions.

Fixes #7176

Examples

async fn get_random_number() -> i64 {
    4 // Chosen by fair dice roll. Guaranteed to be random.
}

Could be written as:

fn get_random_number() -> i64 {
    4 // Chosen by fair dice roll. Guaranteed to be random.
}

Something like this, however, should not be caught by clippy:

#[async_trait]
trait AsyncTrait {
    async fn foo();
}

struct Bar;

#[async_trait]
impl AsyncTrait for Bar {
    async fn foo() {
        println!("bar");
    }
}

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @llogiq (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 15, 2021
@llogiq
Copy link
Contributor

llogiq commented May 17, 2021

Thank you for this lint. I think there might be other forms of false positives besides being a trait functions. One could have a pointer to an async function and the type of that pointer might change if the function is no longer async. But as this is a pedantic lint, that's no need for concern.

@bors r+

@bors
Copy link
Contributor

bors commented May 17, 2021

📌 Commit 75ef9dc has been approved by llogiq

@bors
Copy link
Contributor

bors commented May 17, 2021

⌛ Testing commit 75ef9dc with merge acdf43f...

@bors
Copy link
Contributor

bors commented May 17, 2021

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: llogiq
Pushing acdf43f to master...

@bors bors merged commit acdf43f into rust-lang:master May 17, 2021
@snowsignal snowsignal deleted the unnessecary-async branch May 17, 2021 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New lint: unused-async
4 participants