RS.CLIPPY.NEEDLESS_PASS_BY_VALUE

Functions taking arguments by value, but not consuming them in its body

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

What it does

Checks for functions taking arguments by value, but not consuming them in its body.

Why is this bad?

Taking arguments by reference is more flexible and can sometimes avoid unnecessary allocations.

Known problems

  • This lint suggests taking an argument by reference, however sometimes it is better to let users decide the argument type (by using Borrow trait, for example), depending on how the function is used.

Example

fn foo(v: Vec<i32>) {
    assert_eq!(v.len(), 42);
}

should be

fn foo(v: &[i32]) {
    assert_eq!(v.len(), 42);
}