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

Clippy incorrectly binds block expression in if, in if #12592

Open
arifd opened this issue Mar 29, 2024 · 0 comments
Open

Clippy incorrectly binds block expression in if, in if #12592

arifd opened this issue Mar 29, 2024 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@arifd
Copy link

arifd commented Mar 29, 2024

Summary

The error in question:

after fixes were automatically applied the compiler reported errors within these files:

  * crates/storage/src/storage.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see 
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust-clippy/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error: expected expression, found `let` statement
  --> crates/storage/src/storage.rs:60:26
   |
60 |         let mut bucket = let res = {
   |                          ^^^
   |
   = note: only supported directly in conditions of `if` and `while` expressions

error: aborting due to previous error

Original diagnostics will follow.

The likely relevant lint:

warning: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
  --> crates/storage/src/storage.rs:60:26
   |
60 |           let mut bucket = if {
   |  __________________________^
61 | |             let resp = bucket
62 | |                 .put_object("check_if_bucket_exists.txt", b"it does")
63 | |                 .await?;
64 | |             resp.status_code() == 200
65 | |         } {
   | |_________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_if_conditions
   = note: `#[warn(clippy::blocks_in_if_conditions)]` on by default
help: try
   |
60 ~         let mut bucket = let res = {
61 +             let resp = bucket
62 +                 .put_object("check_if_bucket_exists.txt", b"it does")
63 +                 .await?;
64 +             resp.status_code() == 200
65 ~         }; if res {
   |

The actual block of code:

let mut bucket = if {
    let resp = bucket
        .put_object("check_if_bucket_exists.txt", b"it does")
        .await?;
    resp.status_code() == 200
} {
    bucket
} else {
    Self::init(connect).await?
};

Version

rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: aarch64-apple-darwin
release: 1.75.0
LLVM version: 17.0.6
@arifd arifd added the C-bug Category: Clippy is not doing the correct thing label Mar 29, 2024
@y21 y21 added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Mar 29, 2024
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-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

2 participants