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

macros: fix the clippy::needless_return lint triggered by #[tokio::test] and #[tokio::main] #6880

Closed

Conversation

Veetaha
Copy link
Contributor

@Veetaha Veetaha commented Sep 29, 2024

Motivation

I started seeing clippy::needless_return lints in a CI job that runs the nightly cargo clippy against my code (CI link):

error: unneeded `return` statement
Error:   --> bon/tests/integration/builder/mod.rs:53:27
   |
53 |     assert_eq!(actual, 42);
   |                           ^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
   = note: `-D clippy::needless-return` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(clippy::needless_return)]`
help: remove `return`
   |
53 |     assert_eq!(actual, 42)assert_eq!(actual, 42);
   |                           ~~~~~~~~~~~~~~~~~~~~~~~

That test doesn't do anything fancy:

#[tokio::test]
async fn async_fn() {
    #[builder]
    async fn sut(arg: u32) -> u32 {
        std::future::ready(arg).await
    }

    let actual = sut().arg(42).call().await;
    assert_eq!(actual, 42);
}

I think clippy started covering more cases of "needless return" where the function has a return for an expression that returns a unit type.

Solution

Added an allow for the lint to the generated code.

Questions

I see there are no CI jobs that exercise the clippy on nightly. Would it be fine to add one to catch regressions from nightly early? The job doesn't need to be required to pass. It can be continue-on-error: true and shouldn't block PRs from merging (like I do in my repo).

@Veetaha Veetaha force-pushed the feat/fix-clippy-needless-return branch from 2542bd6 to 24fadad Compare September 29, 2024 15:52
@Darksonn Darksonn added the A-tokio-macros Area: The tokio-macros crate label Sep 30, 2024
@Darksonn
Copy link
Contributor

This is a duplicate of #6874.

@Darksonn Darksonn closed this Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-macros Area: The tokio-macros crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants