RS.CLIPPY.ZERO_REPEAT_SIDE_EFFECTS

Usage of zero-sized initializations of arrays or vecs causing side effects

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: zero_repeat_side_effects. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for array or vec initializations which call a function or method, but which have a repeat count of zero.

Why is this bad?

Such an initialization, despite having a repeat length of 0, will still call the inner function. This may not be obvious and as such there may be unintended side effects in code.

Example

fn side_effect() -> i32 {
    println!("side effect");
    10
}
let a = [side_effect(); 0];

Use instead:

fn side_effect() -> i32 {
    println!("side effect");
    10
}
side_effect();
let a: [i32; 0] = [];