Skip to content

{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

Merged
merged 1 commit into from
Jul 12, 2025

Conversation

ada4a
Copy link
Contributor

@ada4a ada4a commented Jul 8, 2025

changelog: [map_identity,flat_map_identity]: also recognize |[x, y]| [x, y]

fixes #15198

@rustbot
Copy link
Collaborator

rustbot commented Jul 8, 2025

r? @y21

rustbot has assigned @y21.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 8, 2025
@ada4a ada4a changed the title {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 Jul 8, 2025
@ada4a
Copy link
Contributor Author

ada4a commented Jul 8, 2025

should I add struct destructuring as well? It would be completely irrelevant flat_map_identity, but definitely so for map_identity, e.g. for |Foo {bar, baz}| Foo {bar, baz}

EDIT: on another thought... maybe not -- even the "simpler" thing, tuple structs, would require delving into the horrors of ExprKind::Call again, which I would rather avoid

Copy link
Member

@y21 y21 left a 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.

@y21
Copy link
Member

y21 commented Jul 12, 2025

Could you squash the commits?

@ada4a ada4a force-pushed the flat-map-option-array-destructuring branch from edbf7a0 to e610584 Compare July 12, 2025 12:03
@ada4a
Copy link
Contributor Author

ada4a commented Jul 12, 2025

squashed (and rebased)

@y21 y21 added this pull request to the merge queue Jul 12, 2025
Merged via the queue into rust-lang:master with commit 3c3ee9b Jul 12, 2025
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 12, 2025
@ada4a ada4a deleted the flat-map-option-array-destructuring branch July 12, 2025 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flat_map_identity misses de- and re-structuring
3 participants