RS.CLIPPY.PTR_ARG

Fn arguments of the type `&Vec<...>` or `&String`, suggesting to use `&[...]` or `&str` instead, respectively

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

What it does

This lint checks for function arguments of type &String, &Vec, &PathBuf, and Cow<_>. It will also suggest you replace .clone() calls with the appropriate .to_owned()/to_string() calls.

Why is this bad?

Requiring the argument to be of the specific type makes the function less useful for no benefit; slices in the form of &[T] or &str usually suffice and can be obtained from other types, too.

Known problems

There may be fn(&Vec)-typed references pointing to your function. If you have them, you will get a compiler error after applying this lint's suggestions. You then have the choice to undo your changes or change the type of the reference.

Note that if the function is part of your public interface, there may be other crates referencing it, of which you may not be aware. Carefully deprecate the function before applying the lint suggestions in this case.

Example

fn foo(&Vec<u32>) { .. }

Use instead:

fn foo(&[u32]) { .. }