Skip to content
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

map_identity does not consider reference matching ergonomics #11764

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

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