statement placed after a diverging statement

ID

rust.correctness.unreachable_code

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Dead Code

Language

Rust

Description

Reports a statement that directly follows return, break, continue, panic!, process::exit or another diverging call in the same block, so control can never reach it.

Rationale

Code after a diverging statement never runs, yet it still reads as part of the algorithm: a cleanup call, a counter update or a log line placed there looks executed and is not. The usual causes are a return moved up during a fix, or a debugging early exit left behind, so the unreachable lines are frequently the ones that were supposed to make the function correct.

The following code illustrates the pattern detected by this rule:

fn log(_a: i32) {}
fn double(a: i32) -> i32 {
    // FLAGGED: statement placed after a diverging statement
    return a * 2;
    log(a);
}

Remediation

Delete the unreachable statements, or move the diverging statement below them if the code was meant to run first. When the exit is conditional, put it inside the if that guards it instead of at the top of the block.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved