Why is this an issue?

Resizing a vector to zero using vec.resize(0, value) is misleading. It’s either unreadable if the intent was simply to clear the vector, making the code harder to understand, or suspicious and unintentional if a resize was actually expected, but the arguments were accidentally swapped.

How to fix it

Replace vec.resize(0, value) with vec.clear(), or swap the vec.resize arguments.

Code examples

Noncompliant code example

let mut vec = vec![1, 2, 3, 4, 5];
vec.resize(0, 5); // Noncompliant: Resizing the vector to 0.

Compliant solution

let mut vec = vec![1, 2, 3, 4, 5];
vec.clear(); // Compliant: Clear the vector.

Resources

Documentation