Skip to content

map_identity does not consider reference matching ergonomics #11764

Closed
@kawadakk

Description

@kawadakk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions