RS.CLIPPY.OPTION_AS_REF_CLONED

Cloning an `Option` via `as_ref().cloned()`

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

What it does

Checks for usage of .as_ref().cloned() and .as_mut().cloned() on Options

Why is this bad?

This can be written more concisely by cloning the Option directly.

Example

fn foo(bar: &Option<Vec<u8>>) -> Option<Vec<u8>> {
    bar.as_ref().cloned()
}

Use instead:

fn foo(bar: &Option<Vec<u8>>) -> Option<Vec<u8>> {
    bar.clone()
}