Closed
Description
Lint name: blocks_in_if_conditions
I tried this code:
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.