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

False positive for infinite_loop inside async block in function #14000

Open
jwodder opened this issue Jan 14, 2025 · 0 comments
Open

False positive for infinite_loop inside async block in function #14000

jwodder opened this issue Jan 14, 2025 · 0 comments
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

Comments

@jwodder
Copy link

jwodder commented Jan 14, 2025

Summary

The infinite_loop lint triggers on infinite loops inside async blocks inside functions that don't return !, even if the functions don't await those blocks.

Lint Name

infinite_loop

Reproducer

I tried this code:

pub fn install_ticker() {
    let mut schedule = tokio::time::interval(std::time::Duration::from_secs(5));
    tokio::spawn({
        async move {
            loop {
                schedule.tick().await;
                println!("Tick");
            }
        }
    });
}

with this Cargo.toml:

[package]
name = "loop-bug"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = { version = "1.43.0", features = ["rt", "time"] }

[lints.clippy]
infinite_loop = "deny"

When I ran cargo clippy, I saw this happen:

    Checking loop-bug v0.1.0 (/Users/jwodder/work/dev/tmp/loop-bug)
error: infinite loop detected
 --> src/lib.rs:5:13
  |
5 | /             loop {
6 | |                 schedule.tick().await;
7 | |                 println!("Tick");
8 | |             }
  | |_____________^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#infinite_loop
  = note: requested on the command line with `-D clippy::infinite-loop`
help: if this is intentional, consider specifying `!` as function return
  |
1 | pub fn install_ticker() -> ! {
  |                         ++++

error: could not compile `loop-bug` (lib) due to 1 previous error

I expected to see this happen: no errors

Version

rustc 1.84.0 (9fc6b4312 2025-01-07)
binary: rustc
commit-hash: 9fc6b43126469e3858e2fe86cafb4f0fd5068869
commit-date: 2025-01-07
host: x86_64-apple-darwin
release: 1.84.0
LLVM version: 19.1.5

Additional Labels

No response

@jwodder jwodder 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 Jan 14, 2025
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
Projects
None yet
Development

No branches or pull requests

1 participant