-
Notifications
You must be signed in to change notification settings - Fork 1.8k
{flat_,}map_identity
: recognize |[x, y]| [x, y]
as an identity function as well
#15229
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
{flat_,}map_identity
: recognize |[x, y]| [x, y]
as an identity function as well
#15229
Conversation
{flat_,}map_identity
: recognize |[x, y]| [x,y]
as identity function as well{flat_,}map_identity
: recognize |[x, y]| [x, y]
as an identity function as well
should I add struct destructuring as well? It would be completely irrelevant EDIT: on another thought... maybe not -- even the "simpler" thing, tuple structs, would require delving into the horrors of |
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.
This looks good to me, thanks! Nice that you thought of match ergonomics, in the past they've caused some trouble in these identity lints :)
As for struct destructuring, I suppose conceptually it could make sense for this lint to catch them, but yeah, definitely not something you need to do here, this is a solid improvement on its own.
Could you squash the commits? |
edbf7a0
to
e610584
Compare
squashed (and rebased) |
#15261) Follow-up of #15229, as described in #15229 (comment) -- it turned out to be not that difficult after all! changelog: [`map_identity`,`flat_map_identity`]: also recognize (tuple) struct de- and resctructuring r? @y21
…15268) While working on #15229, I noticed a test case in `map_identity` which avoids linting in the case where removing the `.map()` would require the iterator variable to be made mutable. But then I saw #14140, and thought I'd try to adapt its approach, by suggesting both removing the `.map()` _and_ making the variable mutable. This is WIP only because I'm not sure about the very last `diag.span_note` -- I think having a method chained immediately after the `.map()` is the only case which requires adding `mut`, so it should be safe to say that `method_requiring_mut` is always `Some`. I'd like to do a lintcheck run to see if that's actually true. @samueltardieu do you think this is a good approach? Maybe there are more lints where we could lint + suggest making the variable mut, instead of not linting? changelog:`map_identity`: suggest making the variable mutable when necessary
changelog: [
map_identity
,flat_map_identity
]: also recognize|[x, y]| [x, y]
fixes #15198