RS.CLIPPY.OR_FUN_CALL

Using any `*or` method with a function call, which suggests `*or_else`

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

What it does

Checks for calls to .or(foo(..)), .unwrap_or(foo(..)), .or_insert(foo(..)) etc., and suggests to use .or_else(|| foo(..)), .unwrap_or_else(|| foo(..)), .unwrap_or_default() or .or_default() etc. instead.

Why is this bad?

The function will always be called. This is only bad if it allocates or does some non-trivial amount of work.

Known problems

If the function has side-effects, not calling it will change the semantic of the program, but you shouldn't rely on that.

The lint also cannot figure out whether the function you call is actually expensive to call or not.

Example

foo.unwrap_or(String::from("empty"));

Use instead:

foo.unwrap_or_else(|| String::from("empty"));