Skip to content

Incorrect infinite loop detection in async functions #12338

@AlexSherbinin

Description

@AlexSherbinin

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

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