Skip to content

needless_return triggered without a return statement #13481

Description

@dominikwilkowski

Description

This may very well be hidden in the prog macro or something else is going on but at the very least the clippy suggestion is wrong if not the entire warning.

This is my code:

#[cfg(feature = "ssr")]
#[tokio::main]
async fn main() {
    use sqlx::migrate::Migrator;
    static MIGRATOR: Migrator = sqlx::migrate!("./migrations");

    use crate::{
        app::App,
        db::ssr::{get_db, init_db},
        fileserv::file_and_error_handler,
    };

    use axum::Router;
    use leptos::*;
    use leptos_axum::{generate_route_list, LeptosRoutes};

    // Init the pool into static
    init_db().await.expect("Initialization of database failed");

    if let Err(e) = MIGRATOR.run(get_db()).await {
        eprintln!("{e:?}");
    }

    // Setting get_configuration(None) means we'll be using cargo-leptos's env values
    // For deployment these variables are:
    // https://github.com/leptos-rs/start-axum#executing-a-server-on-a-remote-machine-without-the-toolchain
    // Alternately a file can be specified such as Some("Cargo.toml")
    // The file would need to be included with the executable when moved to deployment
    let conf = get_configuration(None).await.unwrap();
    let leptos_options = conf.leptos_options;
    let addr = leptos_options.site_addr;
    let routes = generate_route_list(App);

    // build our application with a route
    let app = Router::new()
        .leptos_routes(&leptos_options, routes, App)
        .fallback(file_and_error_handler)
        .with_state(leptos_options);

    let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
    axum::serve(listener, app.into_make_service()).await.unwrap();
}

(Almost unchanged from the leptos starter template)

And this is the warning I'm getting when running cargo clippy --all-features

warning: unneeded `return` statement
  --> src/main.rs:77:63
   |
77 |     axum::serve(listener, app.into_make_service()).await.unwrap();
   |                                                                  ^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
   = note: `#[warn(clippy::needless_return)]` on by default
help: remove `return`
   |
77 |     axum::serve(listener, app.into_make_service()).await.unwrap()axum::serve(listener, app.into_make_service()).await.unwrap();
   |                                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Now axum::serve(listener, app.into_make_service()).await.unwrap()axum::serve(listener, app.into_make_service()).await.unwrap(); isn't valid rust code for one but I also don't see a return statement?

On the side I tried to suppress the warning and got this:

warning: unneeded `return` statement
  --> src/main.rs:77:63
   |
77 |     axum::serve(listener, app.into_make_service()).await.unwrap();
   |                                                                  ^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
   = note: `#[warn(clippy::needless_return)]` on by default
help: remove `return`
   |
77 ~     axum::serve(listener, app.into_make_service()).await.unwrap()#[allow(clippy::needless_return)]
78 ~     axum::serve(listener, app.into_make_service()).await.unwrap();
   |

Side note: Adding the #[allow(clippy::needless_return)] to the top of the function works to suppress the warning.

Version

rustc 1.83.0-nightly (7608018 2024-09-29)
binary: rustc
commit-hash: 7608018
commit-date: 2024-09-29
host: aarch64-apple-darwin
release: 1.83.0-nightly
LLVM version: 19.1.0

Additional Labels

No response

Activity

  1. y21 commented on Sep 30, 2024

    @y21
    Member

    Duplicate of #13458, will be fixed by #13464

  2. dominikwilkowski commented on Sep 30, 2024

    @dominikwilkowski
    Author

    Ah thank you! I did search the issues for needless_return and didn't find this issue. Closing

  3. added a commit that references this issue on Oct 10, 2024
    8e60f14
  4. added a commit that references this issue on Oct 18, 2024
    806a9df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions