Skip to content

blocks_in_if_conditions triggers in while loops in a too strigent way #7580

Closed
@AlexTMjugador

Description

@AlexTMjugador

Lint name: blocks_in_if_conditions

I tried this code:

https://github.com/ComunidadAylas/PackSquash/blob/b514fba469b38edf207120aaa3fb8a12476b72fe/src/squash_zip.rs#L277-L281

I expected to see this happen: no warnings emitted by Clippy.

Instead, this happened: Clippy emitted the warning. In my humble opinion, I think this warning is a false positive due to the following reasons:

  • The affected code is not an if condition, and the side effects of evaluating that expression are needed for the code to work as intended.
  • The suggested correction of assigning the result of the expression to a variable is, therefore, not appropriate.
  • Using closures or auxiliary functions is, in my opinion, not much more clearer in this case than using this block. Closures also sometimes impose some cognitive or maintenance burden because they borrow their environment in a certain way, and make the compiler do more work to optimize them away.
  • Restructuring the code so it does the method call before entering the while loop and before finishing its body is not much better either, because it leads to duplicated code.
  • Because it uses .await, putting the offending code in a closure requires async closures, which is an unstable feature, and it might not be desirable to use additional unstable features because of this lint.

Meta

  • cargo clippy -V: clippy 0.1.56 (0035d9d 2021-08-16)
  • rustc -Vv:
    rustc 1.56.0-nightly (0035d9dce 2021-08-16)
    binary: rustc
    commit-hash: 0035d9dcecee49d1f7349932bfa52c05a6f83641
    commit-date: 2021-08-16
    host: x86_64-unknown-linux-gnu
    release: 1.56.0-nightly
    LLVM version: 12.0.1
    

This warning did not occur in previous nightly versions of Clippy. I couldn't find any recent commit or issue that referenced this lint and may be the cause of it, either.

Clippy warning output screenshot

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