-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[option_if_let_else
]: suggest .as_ref()
if scrutinee is of type &Option<_>
#11035
Conversation
r? @Jarcho (rustbot has picked a reviewer for you, use r? to override) |
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.
Just to check, this lint currently doesn't handle patterns like &Some(_)
, correct?
tests/ui/option_if_let_else.rs
Outdated
@@ -239,6 +239,8 @@ fn main() { | |||
Ok(a) => a + 1, | |||
}; | |||
let _ = if let Ok(a) = res { a + 1 } else { 5 }; | |||
issue10729::reproduce(&None); | |||
issue10729::reproduce2(&mut None); |
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.
Small nit. There's no need for this as the test code is only compiled, not run.
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.
I did that to silence the dead code warning, but I guess I could also #[allow]
it.
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.
You can also prefix names with underscores as well. That silences unused warnings.
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.
Decided to go with #![allow(dead_code)]
for that module because it's also used for other unused functions in that test file, hope that's fine too
Yes, it doesn't lint in that case: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=790624fb7c9a4ddb11753e60e278ec5b |
Ok. Not a requirement to handle it, just want to make sure that case doesn't end up with a regressions. Once the little nit is handled then this is good. |
Thank you. @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #10729
Option::map_or
takes ownership, so if matching on an&Option<_>
, we need to suggest.as_ref()
before callingmap_or
to get the same effect and to not cause a borrowck error.changelog: [
option_if_let_else
]: suggest.as_ref()
/.as_mut()
if scrutinee is of type&Option<_>
/&mut Option<_>