Loop always exits on its first iteration

ID

rust.correctness.never_loop

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Control Flow

Language

Rust

Description

This loop leaves on its first iteration, so the body runs exactly once and the loop reads as repetition that never happens. Drop the loop and keep the body, or move the exit behind the condition that was meant to end it.

Rationale

This loop leaves on its first iteration, so the body runs exactly once and the loop reads as repetition that never happens. Drop the loop and keep the body, or move the exit behind the condition that was meant to end it.

The following code illustrates the pattern detected by this rule:

pub fn exits_immediately() {
    // FLAGGED: Loop always exits on its first iteration
    loop {
        break;
    }
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved