Add comments + Very minor Refactor
This commit is contained in:
parent
4e1db44404
commit
3bfccacca9
@ -48,9 +48,12 @@ impl EarlyLintPass for OptionEnvUnwrap {
|
|||||||
|
|
||||||
if let ExprKind::MethodCall(box MethodCall { seg, receiver, .. }) = &expr.kind &&
|
if let ExprKind::MethodCall(box MethodCall { seg, receiver, .. }) = &expr.kind &&
|
||||||
matches!(seg.ident.name, sym::expect | sym::unwrap) {
|
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);
|
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);
|
lint(cx, expr.span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
error: this will panic at run-time if the environment variable doesn't exist at compile-time
|
||||||
--> $DIR/option_env_unwrap.rs:12:13
|
--> $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
|
= help: consider using the `env!` macro instead
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user