RS.CLIPPY.CLONED_REF_TO_SLICE_REFS
Cloning a reference for slice references
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: cloned_ref_to_slice_refs. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for slice references with cloned references such as &[f.clone()].
Why is this bad
A reference does not need to be owned in order to be used as a slice.
Known problems
This lint does not know whether or not a clone implementation has side effects.
Example
let data = 10;
let data_ref = &data;
take_slice(&[data_ref.clone()]);
Use instead:
use std::slice;
let data = 10;
let data_ref = &data;
take_slice(slice::from_ref(data_ref));