Skip to content

Conversation

profetia
Copy link
Contributor

@profetia profetia commented Sep 19, 2025

Closes #15713
Closes #15714
Closes #15752

changelog: [map_unwrap_or] add cover for Result::unwrap_or

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 19, 2025

r? @blyxyas

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

Copy link

github-actions bot commented Sep 19, 2025

Lintcheck changes for 1e16651

Lint Added Removed Changed
clippy::map_unwrap_or 15 0 5

This comment will be updated if you push new changes

@samueltardieu
Copy link
Member

Unless you have a good reason not to, please use map_unwrap_or_fixable.rs for the tests.

@profetia
Copy link
Contributor Author

Moved. Thank you!

@rustbot
Copy link
Collaborator

rustbot commented Sep 23, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@profetia
Copy link
Contributor Author

Also fixes #15713

@profetia
Copy link
Contributor Author

Also closes #15752

Copy link
Member

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

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

If possible, you should squash together the two commits "Apply map_unwrap to Clippy itself" and make it the first commit). This way, after every commit, Clippy tests still pass (including dogfood), and it makes it easy to bisect should something go wrong. Then each "fix" commit can be put on top.

View changes since this review

@profetia
Copy link
Contributor Author

Updated. Thank you

Comment on lines +79 to +83
// is_some_and is stabilised && `unwrap_or` argument is false; suggest `is_some_and` instead
let suggest_is_some_and = matches!(&unwrap_arg.kind, ExprKind::Lit(lit)
if matches!(lit.node, rustc_ast::LitKind::Bool(false)))
&& msrv.meets(cx, msrvs::OPTION_RESULT_IS_VARIANT_AND);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be left to manual_is_variant_and? For example, this suggests is_some_and but not is_none_or

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think manual_is_variant_and checks for unwrap_or(false)

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I mean let this lint turn map().unwrap_or_else(bool, ..) into map_or_else(bool, ..) first, and then manual_is_variant_and would transform that further

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm ok with this behavior. Do you want it to be handled in one transform?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for not explaining myself clearly^^ Yes, I also prefer this to be handled in two transforms, so what I'm proposing is to remove the suggest_is_some_and logic from this lint

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
5 participants