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

await triggers blocks_in_conditions #12016

Closed
xxchan opened this issue Dec 26, 2023 · 8 comments · Fixed by #12040
Closed

await triggers blocks_in_conditions #12016

xxchan opened this issue Dec 26, 2023 · 8 comments · Fixed by #12040
Assignees
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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@xxchan
Copy link
Contributor

xxchan commented Dec 26, 2023

Summary

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/stream/src/executor/rearranged_chain.rs:264:13
    |
264 |             match select(&mut stop_rearrange_rx, upstream.next()).await {
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `let res = await; 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/stream/src/executor/temporal_join.rs:296:13
    |
296 |             match combined.next().await {
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `let res = await; 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/stream/src/executor/union.rs:110:9
    |
110 |         match active.next().await {
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `let res = await; match res`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions

Lint Name

blocks_in_conditions

Reproducer

I tried this code:

<code>

I saw this happen:

<output>

I expected to see this happen:

Version

rustc 1.77.0-nightly (e4c626dd9 2023-12-25)
binary: rustc
commit-hash: e4c626dd9a17a23270bf8e7158e59cf2b9c04840
commit-date: 2023-12-25
host: aarch64-apple-darwin
release: 1.77.0-nightly
LLVM version: 17.0.6

Additional Labels

No response

@xxchan xxchan 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 Dec 26, 2023
@xxchan
Copy link
Contributor Author

xxchan commented Dec 26, 2023

cc @J-ZhengLi Is this possibile to be caused by #11853?

@J-ZhengLi
Copy link
Member

cc @J-ZhengLi Is this possibile to be caused by #11853?

Sadly yes...

Hmmm, weird, I'm sure I was specifically targeting match expressions with MatchSource::Normal only, I'll see what went wrong. @rustbot claim

@J-ZhengLi
Copy link
Member

J-ZhengLi commented Dec 27, 2023

@xxchan I can't reproduce the issue, would you mind provide a minimal reproduce code?

nvm, found it in your repo

@KisaragiEffective
Copy link
Contributor

KisaragiEffective commented Dec 27, 2023

@rustbot label I-suggestion-causes-error

@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Dec 27, 2023
@BlackDex
Copy link

BlackDex commented Feb 7, 2024

I have issue with this also when running clippy on the Vaultwarden code base.

It generates warning like this, which makes no sense at all.

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/api/identity.rs:642:20
    |
642 |   struct ConnectData {
    |  ____________________^
643 | |     #[field(name = uncased("grant_type"))]
644 | |     #[field(name = uncased("granttype"))]
645 | |     grant_type: String, // refresh_token, password, client_credentials (API key)
...   |
690 | |     #[field(name = uncased("authrequest"))]
691 | |     auth_request: Option<String>,
    | |________________________________^ help: try: `let res = Option<String>; 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/api/notifications.rs:55:22
   |
55 |   struct WsAccessToken {
   |  ______________________^
56 | |     access_token: Option<String>,
   | |________________________________^ help: try: `let res = Option<String>; match res`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions

@BlackDex
Copy link

BlackDex commented Feb 7, 2024

Since this is going to be released in the upcoming Rust 1.76, i have to allow this lint for now i think.

@lucab
Copy link
Contributor

lucab commented Feb 9, 2024

I think I'm also hitting this, the repository is not public but the source and warnings look like this:

  #[instrument(name = "Database::list_foo_bars", skip(self), err)]
  async fn list_foo_bars(&self) -> anyhow::Result<Vec<Uuid>> {
    let bars: Vec<Uuid> =
      sqlx::query("SELECT id FROM foo WHERE is_bar = true")
        .map::<_, Uuid>(|ref row: PgRow| row.get(0))
        .fetch_all(&self.pool)
        .await?;
    Ok(bars)
  }

That results in:

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`
   --> db.rs:1:1
    |
1   |     async fn list_foo_bars(&self) -> anyhow::Result<Vec<Uuid>> {
    |  ___________________________________________________________________^
2   | |     let bars: Vec<Uuid> =
3   | |       sqlx::query("SELECT id FROM foo WHERE is_bar = true")
4   | |         .map::<_, Uuid>(|ref row: PgRow| row.get(0))
...   |
7   | |     Ok(bars)
8   | |   }
    | |___^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions

@fenollp
Copy link

fenollp commented Feb 12, 2024

@lucab + @tmbernardo I've opened a new issue #12281 as this clutters our codebase too

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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants