Skip to content

Conversation

@teofr
Copy link
Contributor

@teofr teofr commented Nov 8, 2025

Introduce a new lint for mapping the identity function with map_or over Option and Result.

Lints:

fn foo(opt: Option<i32>, default: i32) -> i32 {
    opt.map_or(default, |o| o)
}

Into

fn foo(opt: Option<i32>, default: i32) -> i32 {
    opt.unwrap_or(default)
}

Fixes #15801

We had some discussions with @ada4a about naming on issue #15801 , a summary here.

There's a question about naming for this lint, there's already unnecessary_option_map_or_else and unnecessary_result_map_or_else, but I think having two lints doesn't make sense in this case.
unnecessary_map_or could be a reasonable name for this new lint, but it's already taken

changelog: [map_or_identity]: new lint

@teofr teofr marked this pull request as ready for review November 28, 2025 07:11
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Nov 28, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 28, 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

gauravagerwala added a commit to gauravagerwala/rust-clippy that referenced this pull request Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp 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.

Overhaul unnecessary_result_or_else

3 participants