Skip to content

Avoid map_unwrap_or fix when default is adjusted#16928

Open
cyphercodes wants to merge 1 commit intorust-lang:masterfrom
cyphercodes:fix-map-unwrap-or-coercion-16901
Open

Avoid map_unwrap_or fix when default is adjusted#16928
cyphercodes wants to merge 1 commit intorust-lang:masterfrom
cyphercodes:fix-map-unwrap-or-coercion-16901

Conversation

@cyphercodes
Copy link
Copy Markdown

@cyphercodes cyphercodes commented Apr 28, 2026

Fixes #16901

Suppress the machine-applicable map_or suggestion for map_unwrap_or when the unwrap_or default expression was type-adjusted by the original call. In those cases, moving the default into map_or can make inference use the unadjusted type and reject the closure return type. The lint still fires, but without an autofix.

Added a regression for the reported split_once(...).map(|(_, v)| v).unwrap_or(&raw) case.

Verification:

  • TESTNAME=map_unwrap_or cargo uitest
  • cargo fmt --check
  • git diff --check

changelog: [map_unwrap_or]: avoid suggesting map_or when the unwrap_or default requires a type adjustment

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 28, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 28, 2026

r? @Jarcho

rustbot has assigned @Jarcho.
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: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, dswij, llogiq

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.

Autofix failure for clippy map_unwrap_or lint

3 participants