Skip to content

map_identity does not consider reference matching ergonomics #11764

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

Closed
kawadakk opened this issue Nov 7, 2023 · 0 comments · Fixed by #11792
Closed

map_identity does not consider reference matching ergonomics #11764

kawadakk opened this issue Nov 7, 2023 · 0 comments · Fixed by #11792
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@kawadakk
Copy link

kawadakk commented Nov 7, 2023

Summary

map_identity is falsely reported for the cases where reference matching ergonomics (RFC 2005) changes where a reference is introduced in tuples or arrays (e.g., &(T,) -> (&T,)).

Lint Name

map_identity

Reproducer

I tried this code:

pub fn foo<'a>(it: impl Iterator<Item = &'a (i32,)>) -> impl Iterator<Item = (&'a i32,)> {
    it.map(|(x,)| (x,))
    // RFC 2005 transforms the pattern to `&(ref x,)`
}

I saw this happen:

warning: unnecessary map of the identity function
 --> src/lib.rs:2:7
  |
2 |     it.map(|(x,)| (x,))
  |       ^^^^^^^^^^^^^^^^^ help: remove the call to `map`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_identity
  = note: `#[warn(clippy::map_identity)]` on by default

I expected to see this happen: No lints reported

Version

rustc 1.75.0-nightly (fee5518cd 2023-11-05)
binary: rustc
commit-hash: fee5518cdd4435c60a57fe3bb734fc1a14abeb7a
commit-date: 2023-11-05
host: x86_64-pc-windows-gnu
release: 1.75.0-nightly
LLVM version: 17.0.4

Additional Labels

@rustbot label +I-suggestion-causes-error

@kawadakk kawadakk added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Nov 7, 2023
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Nov 7, 2023
@bors bors closed this as completed in d487579 Nov 11, 2023
zydou pushed a commit to zydou/arti that referenced this issue Apr 24, 2025
- rust-lang/rust-clippy#11764 was fixed upstream, so
this is no longer needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants