rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

Incorrect infinite loop detection in async functions

Open AlexSherbinin opened this issue 1 year ago • 1 comments

Summary

When using clippy::infinite_loop lint with async function clippy emits not expected warning.

Lint Name

clippy::infinite_loop

Reproducer

I tried this code:

#![warn(clippy::infinite_loop)]

async fn foo() -> ! {
    loop {
    }
}

I saw this happen:

warning: infinite loop detected
 --> src/lib.rs:4:5
  |
4 | /     loop {
5 | |     }
  | |_____^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#infinite_loop
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(clippy::infinite_loop)]
  |         ^^^^^^^^^^^^^^^^^^^^^
help: if this is intentional, consider specifing `!` as function return
  |
3 | async fn foo() -> !  -> !
  |                      ~~~~

I expected to see no lint

Version

rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: x86_64-unknown-linux-gnu
release: 1.75.0
LLVM version: 17.0.6

Additional Labels

No response

AlexSherbinin avatar Feb 23 '24 15:02 AlexSherbinin

@rustbot claim

CBSpeir avatar Feb 25 '24 18:02 CBSpeir

@rustbot claim

J-ZhengLi avatar Mar 04 '24 00:03 J-ZhengLi