Add lint ref_mut_iter_method_chain#7688
Conversation
|
r? @flip1995 (rust-highfive has picked a reviewer for you, use r? to override) |
a8b9e28 to
0813a12
Compare
|
☔ The latest upstream changes (presumably #7673) made this pull request unmergeable. Please resolve the merge conflicts. |
f7230fe to
6b21369
Compare
6b21369 to
453c07b
Compare
2a19ba8 to
31dc4ab
Compare
| if_chain! { | ||
| if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, base_expr) = self_arg.kind; | ||
| if !self_arg.span.from_expansion(); | ||
| if let Some(&iter_trait) = cx.tcx.all_diagnostic_items(()).name_to_id.get(&sym::Iterator); |
There was a problem hiding this comment.
| if let Some(&iter_trait) = cx.tcx.all_diagnostic_items(()).name_to_id.get(&sym::Iterator); | |
| if let Some(iter_trait) = cx.tcx.get_diagnostic_item(sym::Iterator); |
should work here.
| Cow::Owned(mut snip) => { | ||
| let ctxt = expr.span.ctxt(); | ||
|
|
||
| // Attempt to determine if parenthesis are needed base on the target position. The snippet may have |
There was a problem hiding this comment.
Isn't this the same as what sugg::Sugg does? Also I think the enum ExprPosition is pretty similar to the ExprPrecedence enum of rustc.
Would using the Sugg utility also work here? If not, do you think it would be better to expand the Sugg utility, rather than implementing this new utils function?
There was a problem hiding this comment.
Adding to the left or right of an operator needs to do different things. 1+1 added to the left of a subtraction doesn't need parenthesis, but added to the right it does. ExprPrecedence doesn't allow that distinction.
There was a problem hiding this comment.
Sugg currently doesn't allow adding parenthesis based on where the will be inserted. I'm in the middle of reworking Sugg now, but it's going to be a larger change to fit this in nicely.
There was a problem hiding this comment.
Hm, I prefer reusing Sugg here anyway. If there are unnecessary parenthesis, rustc will warn on that afterwards. As long as the suggestion is semantically correct, I don't mind if there are a pair of parenthesis too many.
Especially when you're working on Sugg anyway, I don't want to include a half-baked solution now. (Also big thanks for improving all of our utilities and not only the lints ❤️)
There was a problem hiding this comment.
Working on #7986 which should be a nicer solution. We can hold off merging this until that's done.
There was a problem hiding this comment.
We can hold off merging this until that's done.
Yes, let's do this. 👍
|
☔ The latest upstream changes (presumably #7896) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Hey @Jarcho, this is a ping from triage. Has there been any update to the blocked status? |
|
Hey this is triage, I'm closing this due to inactivity. If you want to continue this implementation, you're welcome to create a new PR. Thank you for the time, you already put into this! Interested parties are welcome to pick this implementation up as well :) @rustbot label +S-inactive-closed -S-waiting-on-author -S-waiting-on-review |
Mentioned here: #7659 (comment)
changelog: New lint: [
ref_mut_iter_method_chain]#7688