rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.43k stars 1.54k forks source link

`needless_return` triggered without a return statement #13481

Closed dominikwilkowski closed 1 month ago

dominikwilkowski commented 1 month ago

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 (7608018cb 2024-09-29) binary: rustc commit-hash: 7608018cbdac9e55d0d13529cf43adc33d53efcf commit-date: 2024-09-29 host: aarch64-apple-darwin release: 1.83.0-nightly LLVM version: 19.1.0

Additional Labels

No response

y21 commented 1 month ago

Duplicate of #13458, will be fixed by #13464

dominikwilkowski commented 1 month ago

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