Add comments + Very minor Refactor

This commit is contained in:
blyxyas 2023-07-26 23:16:24 +02:00
parent 4e1db44404
commit 3bfccacca9
No known key found for this signature in database
GPG key ID: 4D38170B5A2FC334
2 changed files with 7 additions and 4 deletions

View file

@ -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);
}
}

View file

@ -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