Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positivie (I think): blocks_in_conditions #12642

Open
BurnyLlama opened this issue Apr 6, 2024 · 3 comments
Open

False positivie (I think): blocks_in_conditions #12642

BurnyLlama opened this issue Apr 6, 2024 · 3 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@BurnyLlama
Copy link

Summary

The project is using the rocket web framework, and I get the issue on a struct deriving FromForm.

This is the output I get for cargo clippy:

warning: unused manifest key: build
    Checking news-site v0.1.0 (/home/USER/Development/news-site)
error: 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/app/control_panel.rs:21:28
   |
21 |   struct PublishTextForm<'a> {
   |  ____________________________^
22 | |     #[field(name = "text-type")]
23 | |     text_type: TextType,
   | |_______________________^ help: try: `let res = TextType; match res`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions
note: the lint level is defined here
  --> src/main.rs:2:9
   |
2  | #![deny(warnings)]
   |         ^^^^^^^^
   = note: `#[deny(clippy::blocks_in_conditions)]` implied by `#[deny(warnings)]`

error: 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/app/control_panel.rs:21:28
   |
21 |   struct PublishTextForm<'a> {
   |  ____________________________^
22 | |     #[field(name = "text-type")]
23 | |     text_type: TextType,
24 | |     title: &'a str,
   | |____________^ help: try: `let res = &; match res`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions

error: 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/app/control_panel.rs:21:28
   |
21 |   struct PublishTextForm<'a> {
   |  ____________________________^
22 | |     #[field(name = "text-type")]
23 | |     text_type: TextType,
24 | |     title: &'a str,
25 | |     #[field(name = "leading-paragraph")]
26 | |     leading_paragraph: &'a str,
   | |________________________^ help: try: `let res = &; match res`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions

error: 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/app/control_panel.rs:21:28
   |
21 |   struct PublishTextForm<'a> {
   |  ____________________________^
22 | |     #[field(name = "text-type")]
23 | |     text_type: TextType,
24 | |     title: &'a str,
...  |
27 | |     #[field(name = "text-body")]
28 | |     text_body: &'a str,
   | |________________^ help: try: `let res = &; match res`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions

error: 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/app/control_panel.rs:21:28
   |
21 |   struct PublishTextForm<'a> {
   |  ____________________________^
22 | |     #[field(name = "text-type")]
23 | |     text_type: TextType,
24 | |     title: &'a str,
...  |
28 | |     text_body: &'a str,
29 | |     tags: &'a str,
   | |___________^ help: try: `let res = &; match res`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions

error: could not compile `news-site` (bin "news-site") due to 5 previous errors

Using clippy 0.1.77 (7cf61eb 2024-03-27)

Full code can be found here: https://github.com/LinneaStudenttidning/news-site

Lint Name

blocks_in_conditions

Reproducer

I tried this code:

#[derive(FromForm)]
struct PublishTextForm<'a> {
    #[field(name = "text-type")]
    text_type: TextType,
    title: &'a str,
    #[field(name = "leading-paragraph")]
    leading_paragraph: &'a str,
    #[field(name = "text-body")]
    text_body: &'a str,
    tags: &'a str,
}

I also tried to suppress the error like this:

#[allow(clippy::blocks_in_conditions)]
#[derive(FromForm)]
struct PublishTextForm<'a> {
    #[field(name = "text-type")]
    text_type: TextType,
    title: &'a str,
    #[field(name = "leading-paragraph")]
    leading_paragraph: &'a str,
    #[field(name = "text-body")]
    text_body: &'a str,
    tags: &'a str,
}

But that still fails! (With the same error...)

Then I saw the error mentioned above.

I expected to see this happen:
Nothing, since the code does not directly reference a match statement. I guess there could be some "hidden" match statement behind for example the derive macro...

Version

rustc 1.77.1 (7cf61ebde 2024-03-27)
binary: rustc
commit-hash: 7cf61ebde7b22796c69757901dd346d0fe70bd97
commit-date: 2024-03-27
host: x86_64-unknown-linux-gnu
release: 1.77.1
LLVM version: 17.0.6

Additional Labels

No response

@BurnyLlama BurnyLlama added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Apr 6, 2024
@nemicha
Copy link

nemicha commented Apr 9, 2024

I have the exact same problem. I wanted to add that the same bug exists in 1.76.0 but not in 1.75.0.

@BurnyLlama
Copy link
Author

Yeah, I upgraded my toolchain and the issues showed up. Should probably have said that before!

@calteran
Copy link

calteran commented Apr 11, 2024

I'm seeing this too with Rocket's FromForm derive. The warning shows up for me when Rust >= 1.76 but is not present in 1.75.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

3 participants