-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Now option_env_unwrap warns even if a variable isn't set at compiletime
#10759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
r? @flip1995 (rustbot has picked a reviewer for you, use r? to override) |
|
Note that I needed to undo some "stylistic choices" (remove the That means that the following won't compile: if let ExprKind::Call(caller, _) | ExprKind::Path(_, caller) = receiver.kind;Because |
|
As @flip1995 is pretty busy, I'll let rustbot choose another reviewer. r? rust-lang/clippy |
tests/ui/option_env_unwrap.rs
Outdated
| fn main() { | ||
| let _ = option_env!("PATH").unwrap(); | ||
| let _ = option_env!("PATH").expect("environment variable PATH isn't set"); | ||
| let _ = option_env!("Y").unwrap(); // This test only works if you don't have a __Y__do_not_use env variable in your environment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the comment outdated and should be
| let _ = option_env!("Y").unwrap(); // This test only works if you don't have a __Y__do_not_use env variable in your environment. | |
| let _ = option_env!("Y").unwrap(); // This test only works if you don't have a Y env variable in your environment. |
f873e7c to
4e1db44
Compare
| if let ExprKind::Call(caller, _) = &receiver.kind && 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() { | ||
| lint(cx, expr.span); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add 2 short comments here, what cases are covered by Call vs Path?
|
@bors r+ Thanks! |
|
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #10742
changelog: Fix false negative where
option_env_unwrapwouldn't warn if the env variable isn't set at compile-time.