RS.CLIPPY.OPTION_ENV_UNWRAP

Using `option_env!(...).unwrap()` to get environment variable

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

What it does

Checks for usage of option_env!(...).unwrap() and suggests usage of the env! macro.

Why is this bad?

Unwrapping the result of option_env! will panic at run-time if the environment variable doesn't exist, whereas env! catches it at compile-time.

Example

let _ = option_env!("HOME").unwrap();

Is better expressed as:

let _ = env!("HOME");