RS.CLIPPY.MEM_REPLACE_OPTION_WITH_NONE

Replacing an `Option` with `None` instead of `take()`

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_none. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for mem::replace() on an Option with None.

Why is this bad?

Option already has the method take() for taking its current value (Some(..) or None) and replacing it with None.

Example

use std::mem;

let mut an_option = Some(0);
let replaced = mem::replace(&mut an_option, None);

Is better expressed with:

let mut an_option = Some(0);
let taken = an_option.take();