Skip to content

Improve map_unwrap_or lint to support map(f).unwrap_or_default() - #17644

Merged
samueltardieu merged 2 commits into
rust-lang:masterfrom
qdot3:map_unwrap_or
Sep 4, 2026
Merged

Improve map_unwrap_or lint to support map(f).unwrap_or_default()#17644
samueltardieu merged 2 commits into
rust-lang:masterfrom
qdot3:map_unwrap_or

Conversation

@qdot3

@qdot3 qdot3 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

View all comments

Option::map_or_default/Result::map_or_default was stabilized in Rust 1.98.0, so the map_unwrap_or lint should also cover map(f).unwrap_or_default(), suggesting map_or_default(f) instead.

changelog: [map_unwrap_or]: extend to support map(f).unwrap_or_default()

@rustbot rustbot added the S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. label Aug 28, 2026
@rustbot

rustbot commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome!

You should hear from one of our reviewers after this PR gets at least 2 reviews from the community.

Please see the contribution instructions for more information.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 28, 2026
@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown

Lintcheck changes for 8788452

Lint Added Removed Changed
clippy::map_unwrap_or 13 0 0

This comment will be updated if you push new changes

@CommanderStorm CommanderStorm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Community review: LGTM, could live with this. Would still prefer an better test that also coveres MSRV

View changes since this review

Comment thread tests/ui/map_unwrap_or_fixable.rs Outdated
Comment thread tests/ui/map_unwrap_or_fixable.rs

@DanielEScherzer DanielEScherzer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Community review: lintcheck new hits look correct, some notes

View changes since this review

Comment thread clippy_lints/src/methods/map_unwrap_or_default.rs Outdated
Comment thread clippy_lints/src/methods/map_unwrap_or_default.rs Outdated
Comment thread clippy_lints/src/methods/mod.rs Outdated
@qdot3
qdot3 marked this pull request as draft September 2, 2026 12:24
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 2, 2026
Comment thread tests/ui/map_unwrap_or_fixable.rs Outdated
@qdot3
qdot3 force-pushed the map_unwrap_or branch 2 times, most recently from 1e77590 to 410d9c8 Compare September 2, 2026 13:15
@qdot3
qdot3 marked this pull request as ready for review September 2, 2026 13:22
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 2, 2026

@DanielEScherzer DanielEScherzer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

community review: looks good to me

View changes since this review

Comment thread tests/ui/map_unwrap_or_fixable.rs Outdated
@rustbot rustbot removed the S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. label Sep 2, 2026
@rustbot

rustbot commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

r? @samueltardieu

rustbot has assigned @samueltardieu for the project review.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 9 candidates
  • 9 candidates expanded to 9 candidates
  • Random selection from 6 candidates

@samueltardieu samueltardieu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good start! I've added some suggestions.

Also, please add tests involving macros to ensure we don't trigger.

I'll start a FCP to determine whether we want to extend the map_unwrap_or lint or create a new map_unwrap_or_default one.

@rustbot label lint-nominated

View changes since this review

Comment thread clippy_lints/src/methods/map_unwrap_or_default.rs Outdated
Comment thread clippy_lints/src/methods/map_unwrap_or_default.rs Outdated
Comment thread clippy_lints/src/methods/map_unwrap_or_default.rs Outdated
Comment thread clippy_lints/src/methods/map_unwrap_or_default.rs Outdated
@rustbot rustbot added lint-nominated Create an FCP-thread on Zulip for this PR and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Sep 2, 2026
@rustbot

rustbot commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

This lint has been nominated for inclusion.

A FCP topic has been created on Zulip.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label Sep 2, 2026
@rustbot

rustbot commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@qdot3
qdot3 marked this pull request as draft September 3, 2026 04:00
@qdot3

qdot3 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

These are new tests. The 5th case seems to be a false negative (to me) but filtered out by method_call, witch is very conservative abount macros. I prefer to keep that conservative behavior.

fn option(opt: Option<i32>) {
    let _ = opt.map(|x| x * x).unwrap_or_default(); //~ map_unwrap_or
    let _ = opt.map(|x| vec![x]).unwrap_or_default(); //~ map_unwrap_or
    let _ = identity!(opt.map(|x| x + 1).unwrap_or_default()); //~ map_unwrap_or
    let _ = identity!(opt.map(|x| x + 1)).unwrap_or_default();
    let _ = identity!(opt).map(|x| x + 1).unwrap_or_default();
}

@qdot3
qdot3 marked this pull request as ready for review September 3, 2026 05:08
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 3, 2026
@qdot3

qdot3 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@samueltardieu samueltardieu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the end, before it can be merged, I'll ask you to squash the commits and split the changes into two commits:

  • a first commit with the effect that these changes would have on Clippy sources;
  • a second commit with the changes to the lint itself.

This way, at any stage (before the first commit, after the first commit, and after both commits) tests would pass without warning, in case we need to bisect an issue.

View changes since this review

Comment thread clippy_lints/src/methods/map_unwrap_or_default.rs Outdated
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 3, 2026
@qdot3
qdot3 marked this pull request as draft September 3, 2026 06:31
@qdot3
qdot3 marked this pull request as ready for review September 3, 2026 07:20
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 3, 2026
@samueltardieu
samueltardieu added this pull request to the merge queue Sep 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 3, 2026
@qdot3

qdot3 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

The merge-queue checks will be passed once Lokathor/tinyvec#226 is merged.

@qdot3

qdot3 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Now new version of tinyvec is published, so could you try to add this PR to the merge queue again, @samueltardieu ?

@samueltardieu
samueltardieu added this pull request to the merge queue Sep 4, 2026
Merged via the queue into rust-lang:master with commit b46a4f5 Sep 4, 2026
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lint-nominated Create an FCP-thread on Zulip for this PR S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants