RS.CLIPPY.MEM_REPLACE_OPTION_WITH_SOME
Replacing an `Option` with `Some` instead of `replace()`
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: mem_replace_option_with_some. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for mem::replace() on an Option with Some(...).
Why is this bad?
Option already has the method replace() for
taking its current value (Some(...) or None) and replacing it with
Some(...).
Example
let mut an_option = Some(0);
let replaced = std::mem::replace(&mut an_option, Some(1));
Is better expressed with:
let mut an_option = Some(0);
let taken = an_option.replace(1);
Configuration
-
msrv: The minimum rust version that the project supports. Defaults to therust-versionfield inCargo.toml(default:
current version)