-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: collapsible_match
suggests ref/derefs when needed
#14221
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
base: master
Are you sure you want to change the base?
fix: collapsible_match
suggests ref/derefs when needed
#14221
Conversation
281a540
to
56abdc6
Compare
This comment has been minimized.
This comment has been minimized.
Checking in here. It looks to me like the state is wrong now. Aren't we actually waiting on review? |
We are expecting both a review and a rebase. The bot settings have been changed a few days ago to let the PR in review state, so I'll reset it. @rustbot review |
bc85de9
to
0dc1cdc
Compare
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.
It looks like you ignore the fact that the reference might be mutable. The following code will suggest using .as_ref()
:
let mut arr = ["a", "b", "c"];
if let Some(mut last) = arr.last_mut() {
match &mut last {
&mut &mut "a" | &mut &mut "b" => {
unimplemented!()
},
_ => (),
}
}
The suggestion might also be incorrect in case of raw references, where the types may not match (untested):
const NULL_PTR: *const &'static str = std::ptr::null();
if let Some(last) = arr.last() {
match &raw const *last {
NULL_PTR => unimplemented!(),
_ => (),
}
}
0dc1cdc
to
6116061
Compare
I couldn't figure out any way to handle |
6116061
to
3efde9f
Compare
Fixes: #14155
If an expression is borrowed/dereferenced, suggest using
.as_ref()
or.copied()
respectively in the outer conditional statement.changelog: [
collapsible_match
] suggests ref/dereferencing when needed.