rwf2 / Rocket

A web framework for Rust.

Home Page:https://rocket.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clippy Lint w/ FromForm derive

SenojLuap opened this issue · comments

Rocket Version

0.5.0

Operating System

Windows 11

Rust Toolchain Version

rustc 1.76.0

What happened?

Running clippy on a struct that uses the FromForm #derive generates a lint warning (blocks_in_conditions) for each member.

Test Case

use rocket::FromForm;

#[derive(FromForm)]
pub struct DemoStruct {
    pub field1 : String,
    pub field2 : u32,
    pub field3 : Option<f32>,
}

Log Output

warning: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
 --> src\lib.rs:4:23
  |
4 |   pub struct DemoStruct {
  |  _______________________^
5 | |     pub field1 : String,
  | |_______________________^ help: try: `let res = String; match res`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions
  = note: `#[warn(clippy::blocks_in_conditions)]` on by default

warning: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
 --> src\lib.rs:4:23
  |
4 |   pub struct DemoStruct {
  |  _______________________^
5 | |     pub field1 : String,
6 | |     pub field2 : u32,
  | |____________________^ help: try: `let res = u32; match res`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions

warning: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
 --> src\lib.rs:4:23
  |
4 |   pub struct DemoStruct {
  |  _______________________^
5 | |     pub field1 : String,
6 | |     pub field2 : u32,
7 | |     pub field3 : Option<f32>,
  | |_______________________^ help: try: `let res = Option; match res`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions

warning: `demo_clippy` (lib) generated 3 warnings (run `cargo clippy --fix --lib -p demo_clippy` to apply 3 suggestions)
    Finished dev [unoptimized + debuginfo] target(s) in 0.21s


### Additional Context

_No response_

### System Checks

- [X] My bug report relates to functionality.
- [X] I have tested against the latest Rocket release or a recent git commit.
- [X] I have tested against the latest stable `rustc` toolchain.
- [X] I was unable to find this issue previously reported.

Is this still the case on master?

I believe this is resolved in master as I cannot reproduce. Closing as such.

This might be related to rust-lang/rust-clippy#12642 . Clippy generates the warning in Rust 1.77 but not in 1.75. Rocket v0.5.0 macOS.

I still experience this.

For example (This is just one out of many forms in my project)

#[derive(Debug, FromForm)]
pub struct MoveUser {
    pub user_id: i32,
}

Gives me the following warning:

warning: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
   --> bin/hipster-backend/src/web/department/api.rs:341:21
    |
341 |   pub struct MoveUser {
    |  _____________________^
342 | |     pub user_id: i32,
    | |____________________^ help: try: `let res = i32; match res`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions

Rust version (Stable):

rustup 1.27.0 (bbb9276d2 2024-03-08)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.77.2 (25ef9e3d8 2024-04-09)`

Rocket version: 0.5.0

@madser123 Is this on Rocket v0.5 or master? An issue being closed means it's been resolved in master, not that it's been pushed in a release.

@SergioBenitez what is the timeline for updates on master being pushed in a release for this project? I try to avoid pinning dependencies to branches if I can help it.

@madser123 Is this on Rocket v0.5 or master? An issue being closed means it's been resolved in master, not that it's been pushed in a release.

Sorry.. i didn't know that. It's in 0.5. haven't tested the master branch