RS.CLIPPY.MANUAL_SLICE_FILL

Manually filling a slice with a value

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

What it does

Checks for manually filling a slice with a value.

Why is this bad?

Using the fill method is more idiomatic and concise.

Example

let mut some_slice = [1, 2, 3, 4, 5];
for i in 0..some_slice.len() {
    some_slice[i] = 0;
}

Use instead:

let mut some_slice = [1, 2, 3, 4, 5];
some_slice.fill(0);

Configuration

  • msrv: The minimum rust version that the project supports. Defaults to the rust-version field in Cargo.toml

    (default: current version)