Rocket liniting issues

Rocket Clippy lint

Recently I started to use Clippy extensively and also applied it to my Rocket-based projects.

On this page I am going to collected the linting issues I've encountered and hope to also provide answers.

examples/rocket/lint/Cargo.toml

[package]
name = "lint"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rocket = "0.5"

examples/rocket/lint/src/main.rs

#[macro_use]
extern crate rocket;

#[get("/")]
fn hello_world() -> &'static str {
    "Hello, world!"
}

#[launch]
fn rocket() -> _ {
    rocket::build()
        .mount(
            "/",
            routes![
                hello_world
            ],
        )
}

// cargo clippy -- -Dclippy::no_effect_underscore_binding
cargo clippy -- -Dclippy::no_effect_underscore_binding

complains:


    Checking lint v0.1.0 (/home/gabor/work/rust.code-maven.com/lint)
error: binding to `_` prefixed variable with no side-effect
  --> src/main.rs:15:17
   |
15 |                 hello_world
   |                 ^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#no_effect_underscore_binding
   = note: requested on the command line with `-D clippy::no-effect-underscore-binding`

error: binding to `_` prefixed variable with no side-effect
  --> src/main.rs:15:17
   |
15 |                 hello_world
   |                 ^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#no_effect_underscore_binding

error: binding to `_` prefixed variable with no side-effect
  --> src/main.rs:10:16
   |
10 | fn rocket() -> _ {
   |                ^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#no_effect_underscore_binding

error: could not compile `lint` (bin "lint") due to 3 previous errors

Reported as no_effect_underscore_binding false positive for Rocket routes

Related Pages

Rocket - web development with Rust

Author

Gabor Szabo (szabgab)

Gabor Szabo, the author of the Rust Maven web site maintains several Open source projects in Rust and while he still feels he has tons of new things to learn about Rust he already offers training courses in Rust and still teaches Python, Perl, git, GitHub, GitLab, CI, and testing.

Gabor Szabo