Open
Description
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