RS.CLIPPY.UNNECESSARY_LAZY_EVALUATIONS
Using unnecessary lazy evaluation, which can be replaced with simpler eager evaluation
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: unnecessary_lazy_evaluations. Copyright ©2025 The Rust Team. All rights reserved.
What it does
As the counterpart to or_fun_call, this lint looks for unnecessary
lazily evaluated closures on Option and Result.
This lint suggests changing the following functions, when eager evaluation results in simpler code:
unwrap_or_elsetounwrap_orand_thentoandor_elsetoorget_or_insert_withtoget_or_insertok_or_elsetook_orthentothen_some(for msrv >= 1.62.0)
Why is this bad?
Using eager evaluation is shorter and simpler in some cases.
Known problems
It is possible, but not recommended for Deref and Index to have
side effects. Eagerly evaluating them can change the semantics of the program.
Example
let opt: Option<u32> = None;
opt.unwrap_or_else(|| 42);
Use instead:
let opt: Option<u32> = None;
opt.unwrap_or(42);
Configuration
-
msrv: The minimum rust version that the project supports. Defaults to therust-versionfield inCargo.toml(default:
current version)