about summary refs log tree commit diff
diff options
context:
space:
mode:
authorblyxyas <blyxyas@gmail.com>2023-07-26 23:16:24 +0200
committerblyxyas <blyxyas@gmail.com>2023-07-26 23:16:24 +0200
commit3bfccacca97cb7d4d7751fc90b89b3381b8b8b35 (patch)
tree19d7dbf2dfb34c622f7187664eab5cadb31724a1
parent4e1db44404bbd11f3644c0402e5b1f5358c1b532 (diff)
downloadrust-3bfccacca97cb7d4d7751fc90b89b3381b8b8b35.tar.gz
rust-3bfccacca97cb7d4d7751fc90b89b3381b8b8b35.zip
Add comments + Very minor Refactor
-rw-r--r--clippy_lints/src/option_env_unwrap.rs7
-rw-r--r--tests/ui/option_env_unwrap.stderr4
2 files changed, 7 insertions, 4 deletions
diff --git a/clippy_lints/src/option_env_unwrap.rs b/clippy_lints/src/option_env_unwrap.rs
index 0885bb40cb8..9c7f7e1cd7f 100644
--- a/clippy_lints/src/option_env_unwrap.rs
+++ b/clippy_lints/src/option_env_unwrap.rs
@@ -48,9 +48,12 @@ impl EarlyLintPass for OptionEnvUnwrap {
 
         if let ExprKind::MethodCall(box MethodCall { seg, receiver, .. }) = &expr.kind &&
 		matches!(seg.ident.name, sym::expect | sym::unwrap) {
-			if let ExprKind::Call(caller, _) = &receiver.kind && is_direct_expn_of(caller.span, "option_env").is_some() {
+			if let ExprKind::Call(caller, _) = &receiver.kind &&
+            // If it exists, it will be ::core::option::Option::Some("<env var>").unwrap() (A method call in the HIR)
+            is_direct_expn_of(caller.span, "option_env").is_some() {
 				lint(cx, expr.span);
-			} else if let ExprKind::Path(_, caller) = &receiver.kind && is_direct_expn_of(caller.span, "option_env").is_some() {
+			} else if let ExprKind::Path(_, caller) = &receiver.kind && // If it doesn't exist, it will be ::core::option::Option::None::<&'static str>.unwrap() (A path in the HIR)
+            is_direct_expn_of(caller.span, "option_env").is_some() {
 				lint(cx, expr.span);
 			}
 		}
diff --git a/tests/ui/option_env_unwrap.stderr b/tests/ui/option_env_unwrap.stderr
index 7698b4b0216..cfa9dd58a30 100644
--- a/tests/ui/option_env_unwrap.stderr
+++ b/tests/ui/option_env_unwrap.stderr
@@ -18,8 +18,8 @@ LL |     let _ = option_env!("PATH").expect("environment variable PATH 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:12:13
    |
-LL |     let _ = option_env!("Y").unwrap(); // This test only works if you don't have a __Y__do_not_use env variable in your environment.
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^
+LL |     let _ = option_env!("__Y__do_not_use").unwrap(); // This test only works if you don't have a __Y__do_not_use env variable in your env...
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: consider using the `env!` macro instead