Skip to content

Conversation

@teofr
Copy link
Contributor

@teofr teofr commented Oct 15, 2025

When checking if a function is an identity function, try to use existing functionalities.

Some cases are no longer covered, but I believe that's ok and there were some bugs:

  • No longer considering the identity a closure where the pattern captures by reference, since that made the suggestion break compilation
  • No longer going into other function's body to check if they're isomorphic to the identity, discussed a bit [on Zulip](#clippy > Going into other function definitions desirable?). I understand this could not catch some cases, but I think it's something that is out the scope of this lint. It also requires some ad hoc mechanism in the implementation, doable but a bit hacky.

Fixes #15916

changelog: [unnecessary_option_map_or_else]: function definitions are no longer traversed when checking if an expression is the identity
changelog: [unnecessary_result_map_or_else]: function definitions are no longer traversed when checking if an expression is the identity

@teofr teofr changed the title [WIP] Working on some changes [WIP] Refactors to unnecessary_{option,result}_map_or_else Oct 20, 2025
@qmwrygdxpzc
Copy link

While you are at it, consider making the doc adhere to the template.

diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index c9066be51..fe8990ef0 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -4642,6 +4642,7 @@ declare_clippy_lint! {
 }
 
 declare_clippy_lint! {
+    /// ### What it does
     /// Checks for usage of `.map_or_else()` "map closure" for `Option` type.
     ///
     /// ### Why is this bad?

teofr added 2 commits October 30, 2025 13:12
When checking if a function is an identity function, try to use existing
functionalities.

Some cases are no longer covered, but I believe that's ok and there were
some bugs.

Merge implementations, since they're basically the same.
@teofr teofr marked this pull request as ready for review October 31, 2025 17:15
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 31, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 31, 2025

r? @samueltardieu

rustbot has assigned @samueltardieu.
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

@teofr teofr changed the title [WIP] Refactors to unnecessary_{option,result}_map_or_else Refactor implementation of unnecessary_{option,result}_map_or_else Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor unnecessary_{option,result}_map_or_else and merge implementations

4 participants