RS.CLIPPY.TRIVIALLY_COPY_PASS_BY_REF

Functions taking small copyable arguments by reference

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

What it does

Checks for functions taking arguments by reference, where the argument type is Copy and small enough to be more efficient to always pass by value.

Why is this bad?

In many calling conventions instances of structs will be passed through registers if they fit into two or less general purpose registers.

Known problems

This lint is target dependent, some cases will lint on 64-bit targets but not 32-bit or lower targets.

The configuration option trivial_copy_size_limit can be set to override this limit for a project.

This lint attempts to allow passing arguments by reference if a reference to that argument is returned. This is implemented by comparing the lifetime of the argument and return value for equality. However, this can cause false positives in cases involving multiple lifetimes that are bounded by each other.

Also, it does not take account of other similar cases where getting memory addresses matters; namely, returning the pointer to the argument in question, and passing the argument, as both references and pointers, to a function that needs the memory address. For further details, refer to this issue that explains a real case in which this false positive led to an undefined behavior introduced with unsafe code.

Example

fn foo(v: &u32) {}

Use instead:

fn foo(v: u32) {}

Configuration

  • avoid-breaking-exported-api: Suppress lints whenever the suggested change would cause breakage for other crates.

    (default: true)

  • trivial-copy-size-limit: The maximum size (in bytes) to consider a Copy type for passing by value instead of by reference.

    (default: target_pointer_width)