Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions clippy_lints/src/loops/infinite_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use hir::intravisit::{Visitor, walk_expr};
use rustc_ast::Label;
use rustc_errors::Applicability;
use rustc_hir::{
self as hir, Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, Expr, ExprKind, FnRetTy, FnSig, Node, TyKind,
self as hir, Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, FnRetTy,
FnSig, Node, TyKind,
};
use rustc_lint::{LateContext, LintContext};
use rustc_span::sym;
Expand Down Expand Up @@ -73,7 +74,11 @@ fn is_inside_unawaited_async_block(cx: &LateContext<'_>, expr: &Expr<'_>) -> boo
if let Node::Expr(Expr {
kind:
ExprKind::Closure(Closure {
kind: ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, _)),
kind:
ClosureKind::Coroutine(CoroutineKind::Desugared(
CoroutineDesugaring::Async,
CoroutineSource::Block | CoroutineSource::Closure,
)),
..
}),
..
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/infinite_loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,4 +521,19 @@ mod tokio_spawn_test {
}
}

mod issue15541 {
async fn good() -> ! {
loop {
std::future::pending().await
}
}

async fn bad() {
//~v infinite_loop
loop {
std::future::pending().await
}
}
}

fn main() {}
12 changes: 11 additions & 1 deletion tests/ui/infinite_loops.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -333,5 +333,15 @@ LL | | }
|
= help: if this is not intended, try adding a `break` or `return` condition in the loop

error: aborting due to 23 previous errors
error: infinite loop detected
--> tests/ui/infinite_loops.rs:533:9
|
LL | / loop {
LL | | std::future::pending().await
LL | | }
| |_________^
|
= help: if this is not intended, try adding a `break` or `return` condition in the loop

error: aborting due to 24 previous errors

Loading