From be1bc571c3558cf3920e77d5eb3f017aeeac637c Mon Sep 17 00:00:00 2001 From: Krishna Sai Veera Reddy Date: Sat, 8 Feb 2020 16:44:35 -0800 Subject: [PATCH 1/4] Add `option-env-unwrap` lint --- CHANGELOG.md | 1 + README.md | 2 +- clippy_lints/src/lib.rs | 5 +++ clippy_lints/src/option_env_unwrap.rs | 55 +++++++++++++++++++++++++++ src/lintlist/mod.rs | 9 ++++- tests/ui/option_env_unwrap.rs | 12 ++++++ tests/ui/option_env_unwrap.stderr | 23 +++++++++++ 7 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 clippy_lints/src/option_env_unwrap.rs create mode 100644 tests/ui/option_env_unwrap.rs create mode 100644 tests/ui/option_env_unwrap.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 0953432bfad..3658df88d40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1276,6 +1276,7 @@ Released 2018-09-13 [`op_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#op_ref [`option_and_then_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_and_then_some [`option_as_ref_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref +[`option_env_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_env_unwrap [`option_expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_expect_used [`option_map_or_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_or_none [`option_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unit_fn diff --git a/README.md b/README.md index 96584dfef5c..fd7f33f91d5 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are 354 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) +[There are 355 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you: diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 5084e4e599c..f900a99f314 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -267,6 +267,7 @@ pub mod no_effect; pub mod non_copy_const; pub mod non_expressive_names; pub mod open_options; +pub mod option_env_unwrap; pub mod overflow_check_conditional; pub mod panic_unimplemented; pub mod partialeq_ne_impl; @@ -713,6 +714,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &non_expressive_names::MANY_SINGLE_CHAR_NAMES, &non_expressive_names::SIMILAR_NAMES, &open_options::NONSENSICAL_OPEN_OPTIONS, + &option_env_unwrap::OPTION_ENV_UNWRAP, &overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL, &panic_unimplemented::PANIC, &panic_unimplemented::PANIC_PARAMS, @@ -1003,6 +1005,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: let max_fn_params_bools = conf.max_fn_params_bools; let max_struct_bools = conf.max_struct_bools; store.register_early_pass(move || box excessive_bools::ExcessiveBools::new(max_struct_bools, max_fn_params_bools)); + store.register_early_pass(|| box option_env_unwrap::OptionEnvUnwrap); store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![ LintId::of(&arithmetic::FLOAT_ARITHMETIC), @@ -1285,6 +1288,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&non_expressive_names::JUST_UNDERSCORES_AND_DIGITS), LintId::of(&non_expressive_names::MANY_SINGLE_CHAR_NAMES), LintId::of(&open_options::NONSENSICAL_OPEN_OPTIONS), + LintId::of(&option_env_unwrap::OPTION_ENV_UNWRAP), LintId::of(&overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL), LintId::of(&panic_unimplemented::PANIC_PARAMS), LintId::of(&partialeq_ne_impl::PARTIALEQ_NE_IMPL), @@ -1590,6 +1594,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&non_copy_const::BORROW_INTERIOR_MUTABLE_CONST), LintId::of(&non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST), LintId::of(&open_options::NONSENSICAL_OPEN_OPTIONS), + LintId::of(&option_env_unwrap::OPTION_ENV_UNWRAP), LintId::of(&ptr::MUT_FROM_REF), LintId::of(®ex::INVALID_REGEX), LintId::of(&serde_api::SERDE_API_MISUSE), diff --git a/clippy_lints/src/option_env_unwrap.rs b/clippy_lints/src/option_env_unwrap.rs new file mode 100644 index 00000000000..e0e8a95acd5 --- /dev/null +++ b/clippy_lints/src/option_env_unwrap.rs @@ -0,0 +1,55 @@ +use crate::utils::{is_direct_expn_of, span_lint_and_help}; +use if_chain::if_chain; +use rustc::lint::in_external_macro; +use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_session::{declare_lint_pass, declare_tool_lint}; +use syntax::ast::*; + +declare_clippy_lint! { + /// **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. + /// + /// **Known problems:** None. + /// + /// **Example:** + /// + /// ```rust,no_run + /// let _ = option_env!("HOME").unwrap(); + /// ``` + /// + /// Is better expressed as: + /// + /// ```rust,no_run + /// let _ = env!("HOME"); + /// ``` + pub OPTION_ENV_UNWRAP, + correctness, + "using `option_env!(...).unwrap()` to get environment variable" +} + +declare_lint_pass!(OptionEnvUnwrap => [OPTION_ENV_UNWRAP]); + +impl EarlyLintPass for OptionEnvUnwrap { + fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { + if_chain! { + if !in_external_macro(cx.sess, expr.span); + if let ExprKind::MethodCall(path_segment, args) = &expr.kind; + if path_segment.ident.as_str() == "unwrap"; + if let ExprKind::Call(caller, _) = &args[0].kind; + if is_direct_expn_of(caller.span, "option_env").is_some(); + then { + span_lint_and_help( + cx, + OPTION_ENV_UNWRAP, + expr.span, + "this will panic at run-time if the environment variable doesn't exist", + "consider using the `env!` macro instead" + ); + } + } + } +} diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index f725ce2563f..d4f94a9b60a 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -6,7 +6,7 @@ pub use lint::Lint; pub use lint::LINT_LEVELS; // begin lint list, do not remove this comment, it’s used in `update_lints` -pub const ALL_LINTS: [Lint; 354] = [ +pub const ALL_LINTS: [Lint; 355] = [ Lint { name: "absurd_extreme_comparisons", group: "correctness", @@ -1498,6 +1498,13 @@ pub const ALL_LINTS: [Lint; 354] = [ deprecation: None, module: "methods", }, + Lint { + name: "option_env_unwrap", + group: "correctness", + desc: "using `option_env!(...).unwrap()` to get environment variable", + deprecation: None, + module: "option_env_unwrap", + }, Lint { name: "option_expect_used", group: "restriction", diff --git a/tests/ui/option_env_unwrap.rs b/tests/ui/option_env_unwrap.rs new file mode 100644 index 00000000000..2830669ff66 --- /dev/null +++ b/tests/ui/option_env_unwrap.rs @@ -0,0 +1,12 @@ +#![warn(clippy::option_env_unwrap)] + +macro_rules! option_env_unwrap { + ($env: expr) => { + option_env!($env).unwrap() + }; +} + +fn main() { + let _ = option_env!("HOME").unwrap(); + let _ = option_env_unwrap!("HOME"); +} diff --git a/tests/ui/option_env_unwrap.stderr b/tests/ui/option_env_unwrap.stderr new file mode 100644 index 00000000000..b7d5ecd6321 --- /dev/null +++ b/tests/ui/option_env_unwrap.stderr @@ -0,0 +1,23 @@ +error: this will panic at run-time if the environment variable doesn't exist + --> $DIR/option_env_unwrap.rs:10:13 + | +LL | let _ = option_env!("HOME").unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::option-env-unwrap` implied by `-D warnings` + = help: consider using the `env!` macro instead + +error: this will panic at run-time if the environment variable doesn't exist + --> $DIR/option_env_unwrap.rs:5:9 + | +LL | option_env!($env).unwrap() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | let _ = option_env_unwrap!("HOME"); + | -------------------------- in this macro invocation + | + = help: consider using the `env!` macro instead + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 2 previous errors + From 0e5ba2f0e7c1ec47ad1300e7065b97d5bc603c7c Mon Sep 17 00:00:00 2001 From: Krishna Sai Veera Reddy Date: Sun, 9 Feb 2020 08:54:23 -0800 Subject: [PATCH 2/4] Account for `expect` being used to unwrap `Option` --- clippy_lints/src/option_env_unwrap.rs | 5 +++-- tests/ui/option_env_unwrap.rs | 5 +++++ tests/ui/option_env_unwrap.stderr | 28 +++++++++++++++++++++++---- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/option_env_unwrap.rs b/clippy_lints/src/option_env_unwrap.rs index e0e8a95acd5..e84a7dd2db0 100644 --- a/clippy_lints/src/option_env_unwrap.rs +++ b/clippy_lints/src/option_env_unwrap.rs @@ -38,7 +38,8 @@ impl EarlyLintPass for OptionEnvUnwrap { if_chain! { if !in_external_macro(cx.sess, expr.span); if let ExprKind::MethodCall(path_segment, args) = &expr.kind; - if path_segment.ident.as_str() == "unwrap"; + let method_name = path_segment.ident.as_str(); + if method_name == "expect" || method_name == "unwrap"; if let ExprKind::Call(caller, _) = &args[0].kind; if is_direct_expn_of(caller.span, "option_env").is_some(); then { @@ -46,7 +47,7 @@ impl EarlyLintPass for OptionEnvUnwrap { cx, OPTION_ENV_UNWRAP, expr.span, - "this will panic at run-time if the environment variable doesn't exist", + "this will panic at run-time if the environment variable doesn't exist at compile-time", "consider using the `env!` macro instead" ); } diff --git a/tests/ui/option_env_unwrap.rs b/tests/ui/option_env_unwrap.rs index 2830669ff66..c8488da505c 100644 --- a/tests/ui/option_env_unwrap.rs +++ b/tests/ui/option_env_unwrap.rs @@ -4,9 +4,14 @@ macro_rules! option_env_unwrap { ($env: expr) => { option_env!($env).unwrap() }; + ($env: expr, $message: expr) => { + option_env!($env).expect($message) + }; } fn main() { let _ = option_env!("HOME").unwrap(); + let _ = option_env!("HOME").expect("environment variable HOME isn't set"); let _ = option_env_unwrap!("HOME"); + let _ = option_env_unwrap!("HOME", "environment variable HOME isn't set"); } diff --git a/tests/ui/option_env_unwrap.stderr b/tests/ui/option_env_unwrap.stderr index b7d5ecd6321..2230cc3d859 100644 --- a/tests/ui/option_env_unwrap.stderr +++ b/tests/ui/option_env_unwrap.stderr @@ -1,5 +1,5 @@ -error: this will panic at run-time if the environment variable doesn't exist - --> $DIR/option_env_unwrap.rs:10:13 +error: this will panic at run-time if the environment variable doesn't exist at compile-time + --> $DIR/option_env_unwrap.rs:13:13 | LL | let _ = option_env!("HOME").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7,7 +7,15 @@ LL | let _ = option_env!("HOME").unwrap(); = note: `-D clippy::option-env-unwrap` implied by `-D warnings` = help: consider using the `env!` macro instead -error: this will panic at run-time if the environment variable doesn't exist +error: this will panic at run-time if the environment variable doesn't exist at compile-time + --> $DIR/option_env_unwrap.rs:14:13 + | +LL | let _ = option_env!("HOME").expect("environment variable HOME isn't set"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider using the `env!` macro instead + +error: this will panic at run-time if the environment variable doesn't exist at compile-time --> $DIR/option_env_unwrap.rs:5:9 | LL | option_env!($env).unwrap() @@ -19,5 +27,17 @@ LL | let _ = option_env_unwrap!("HOME"); = help: consider using the `env!` macro instead = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 2 previous errors +error: this will panic at run-time if the environment variable doesn't exist at compile-time + --> $DIR/option_env_unwrap.rs:8:9 + | +LL | option_env!($env).expect($message) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | let _ = option_env_unwrap!("HOME", "environment variable HOME isn't set"); + | ----------------------------------------------------------------- in this macro invocation + | + = help: consider using the `env!` macro instead + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 4 previous errors From a3a1587a1c5b7df413729e34923ada495f3fff94 Mon Sep 17 00:00:00 2001 From: Krishna Sai Veera Reddy Date: Sun, 9 Feb 2020 10:58:08 -0800 Subject: [PATCH 3/4] Allow `option-env-unwrap` within external macros --- clippy_lints/src/option_env_unwrap.rs | 2 -- tests/ui/auxiliary/macro_rules.rs | 10 ++++++++++ tests/ui/option_env_unwrap.rs | 6 ++++++ tests/ui/option_env_unwrap.stderr | 28 ++++++++++++++++++++++----- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/option_env_unwrap.rs b/clippy_lints/src/option_env_unwrap.rs index e84a7dd2db0..1af7793499f 100644 --- a/clippy_lints/src/option_env_unwrap.rs +++ b/clippy_lints/src/option_env_unwrap.rs @@ -1,6 +1,5 @@ use crate::utils::{is_direct_expn_of, span_lint_and_help}; use if_chain::if_chain; -use rustc::lint::in_external_macro; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use syntax::ast::*; @@ -36,7 +35,6 @@ declare_lint_pass!(OptionEnvUnwrap => [OPTION_ENV_UNWRAP]); impl EarlyLintPass for OptionEnvUnwrap { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { if_chain! { - if !in_external_macro(cx.sess, expr.span); if let ExprKind::MethodCall(path_segment, args) = &expr.kind; let method_name = path_segment.ident.as_str(); if method_name == "expect" || method_name == "unwrap"; diff --git a/tests/ui/auxiliary/macro_rules.rs b/tests/ui/auxiliary/macro_rules.rs index eafc68bd6bc..0bbb9534928 100644 --- a/tests/ui/auxiliary/macro_rules.rs +++ b/tests/ui/auxiliary/macro_rules.rs @@ -46,3 +46,13 @@ macro_rules! take_external { std::mem::replace($s, Default::default()) }; } + +#[macro_export] +macro_rules! option_env_unwrap_external { + ($env: expr) => { + option_env!($env).unwrap() + }; + ($env: expr, $message: expr) => { + option_env!($env).expect($message) + }; +} diff --git a/tests/ui/option_env_unwrap.rs b/tests/ui/option_env_unwrap.rs index c8488da505c..59463f9a556 100644 --- a/tests/ui/option_env_unwrap.rs +++ b/tests/ui/option_env_unwrap.rs @@ -1,5 +1,9 @@ +// aux-build:macro_rules.rs #![warn(clippy::option_env_unwrap)] +#[macro_use] +extern crate macro_rules; + macro_rules! option_env_unwrap { ($env: expr) => { option_env!($env).unwrap() @@ -14,4 +18,6 @@ fn main() { let _ = option_env!("HOME").expect("environment variable HOME isn't set"); let _ = option_env_unwrap!("HOME"); let _ = option_env_unwrap!("HOME", "environment variable HOME isn't set"); + let _ = option_env_unwrap_external!("HOME"); + let _ = option_env_unwrap_external!("HOME", "environment variable HOME isn't set"); } diff --git a/tests/ui/option_env_unwrap.stderr b/tests/ui/option_env_unwrap.stderr index 2230cc3d859..3a2d5d11423 100644 --- a/tests/ui/option_env_unwrap.stderr +++ b/tests/ui/option_env_unwrap.stderr @@ -1,5 +1,5 @@ error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:13:13 + --> $DIR/option_env_unwrap.rs:17:13 | LL | let _ = option_env!("HOME").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | let _ = option_env!("HOME").unwrap(); = help: consider using the `env!` macro instead error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:14:13 + --> $DIR/option_env_unwrap.rs:18:13 | LL | let _ = option_env!("HOME").expect("environment variable HOME isn't set"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let _ = option_env!("HOME").expect("environment variable HOME isn't set = help: consider using the `env!` macro instead error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:5:9 + --> $DIR/option_env_unwrap.rs:9:9 | LL | option_env!($env).unwrap() | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | let _ = option_env_unwrap!("HOME"); = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:8:9 + --> $DIR/option_env_unwrap.rs:12:9 | LL | option_env!($env).expect($message) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -39,5 +39,23 @@ LL | let _ = option_env_unwrap!("HOME", "environment variable HOME isn't set = help: consider using the `env!` macro instead = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 4 previous errors +error: this will panic at run-time if the environment variable doesn't exist at compile-time + --> $DIR/option_env_unwrap.rs:21:13 + | +LL | let _ = option_env_unwrap_external!("HOME"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider using the `env!` macro instead + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: this will panic at run-time if the environment variable doesn't exist at compile-time + --> $DIR/option_env_unwrap.rs:22:13 + | +LL | let _ = option_env_unwrap_external!("HOME", "environment variable HOME isn't set"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider using the `env!` macro instead + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 6 previous errors From b48b221f809343bd4da8242a1ea456efd76f3f90 Mon Sep 17 00:00:00 2001 From: Krishna Sai Veera Reddy Date: Sun, 9 Feb 2020 14:12:40 -0800 Subject: [PATCH 4/4] Use `PATH` environment variable for testing The tests were failing on windows because the `HOME` env variable doesn't exist on it so using the `PATH` variable to test instead. --- tests/ui/option_env_unwrap.rs | 12 ++++++------ tests/ui/option_env_unwrap.stderr | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/ui/option_env_unwrap.rs b/tests/ui/option_env_unwrap.rs index 59463f9a556..642c77460a3 100644 --- a/tests/ui/option_env_unwrap.rs +++ b/tests/ui/option_env_unwrap.rs @@ -14,10 +14,10 @@ macro_rules! option_env_unwrap { } fn main() { - let _ = option_env!("HOME").unwrap(); - let _ = option_env!("HOME").expect("environment variable HOME isn't set"); - let _ = option_env_unwrap!("HOME"); - let _ = option_env_unwrap!("HOME", "environment variable HOME isn't set"); - let _ = option_env_unwrap_external!("HOME"); - let _ = option_env_unwrap_external!("HOME", "environment variable HOME isn't set"); + let _ = option_env!("PATH").unwrap(); + let _ = option_env!("PATH").expect("environment variable PATH isn't set"); + let _ = option_env_unwrap!("PATH"); + let _ = option_env_unwrap!("PATH", "environment variable PATH isn't set"); + let _ = option_env_unwrap_external!("PATH"); + let _ = option_env_unwrap_external!("PATH", "environment variable PATH isn't set"); } diff --git a/tests/ui/option_env_unwrap.stderr b/tests/ui/option_env_unwrap.stderr index 3a2d5d11423..8de9c8a9d29 100644 --- a/tests/ui/option_env_unwrap.stderr +++ b/tests/ui/option_env_unwrap.stderr @@ -1,7 +1,7 @@ error: this will panic at run-time if the environment variable doesn't exist at compile-time --> $DIR/option_env_unwrap.rs:17:13 | -LL | let _ = option_env!("HOME").unwrap(); +LL | let _ = option_env!("PATH").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::option-env-unwrap` implied by `-D warnings` @@ -10,7 +10,7 @@ LL | let _ = option_env!("HOME").unwrap(); error: this will panic at run-time if the environment variable doesn't exist at compile-time --> $DIR/option_env_unwrap.rs:18:13 | -LL | let _ = option_env!("HOME").expect("environment variable HOME isn't set"); +LL | let _ = option_env!("PATH").expect("environment variable PATH isn't set"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider using the `env!` macro instead @@ -21,7 +21,7 @@ error: this will panic at run-time if the environment variable doesn't exist at LL | option_env!($env).unwrap() | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ... -LL | let _ = option_env_unwrap!("HOME"); +LL | let _ = option_env_unwrap!("PATH"); | -------------------------- in this macro invocation | = help: consider using the `env!` macro instead @@ -33,7 +33,7 @@ error: this will panic at run-time if the environment variable doesn't exist at LL | option_env!($env).expect($message) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... -LL | let _ = option_env_unwrap!("HOME", "environment variable HOME isn't set"); +LL | let _ = option_env_unwrap!("PATH", "environment variable PATH isn't set"); | ----------------------------------------------------------------- in this macro invocation | = help: consider using the `env!` macro instead @@ -42,7 +42,7 @@ LL | let _ = option_env_unwrap!("HOME", "environment variable HOME isn't set error: this will panic at run-time if the environment variable doesn't exist at compile-time --> $DIR/option_env_unwrap.rs:21:13 | -LL | let _ = option_env_unwrap_external!("HOME"); +LL | let _ = option_env_unwrap_external!("PATH"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider using the `env!` macro instead @@ -51,7 +51,7 @@ LL | let _ = option_env_unwrap_external!("HOME"); error: this will panic at run-time if the environment variable doesn't exist at compile-time --> $DIR/option_env_unwrap.rs:22:13 | -LL | let _ = option_env_unwrap_external!("HOME", "environment variable HOME isn't set"); +LL | let _ = option_env_unwrap_external!("PATH", "environment variable PATH isn't set"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider using the `env!` macro instead