RS.CLIPPY.SINGLE_RANGE_IN_VEC_INIT

Checks for initialization of `Vec` or arrays which consist of a single range

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

What it does

Checks for Vec or array initializations that contain only one range.

Why is this bad?

This is almost always incorrect, as it will result in a Vec that has only one element. Almost always, the programmer intended for it to include all elements in the range or for the end of the range to be the length instead.

Example

let x = [0..200];

Use instead:

// If it was intended to include every element in the range...
let x = (0..200).collect::<Vec<i32>>();
// ...Or if 200 was meant to be the len
let x = [0; 200];