Skip to content

no_effect_underscore_binding false positive for Rocket routes #12166

@szabgab

Description

@szabgab

Summary

no_effect_underscore_binding complains about the functions names that contain and underscore and also about a function that is returning _ in Rocket code.

Lint Name

no_effect_underscore_binding

Reproducer

I tried this code:

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.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"

I saw this happen:

$ cargo clippy -- -Dclippy::no_effect_underscore_binding

    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

I expected to see this happen:

The former (function name with _) seems to be a false positive, I am not sure about the latter (the -> _ code).

Version

rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: x86_64-unknown-linux-gnu
release: 1.75.0
LLVM version: 17.0.6

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions