Skip to content

Conversation

@profetia
Copy link
Member

@profetia profetia commented Sep 19, 2025

Closes #15713
Closes #15714
Closes #15752
Closes #16258

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

@github-actions
Copy link

github-actions bot commented Sep 19, 2025

Lintcheck changes for 0db25db

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
Member Author

Moved. Thank you!

@rustbot

This comment has been minimized.

@profetia
Copy link
Member Author

Also fixes #15713

@profetia
Copy link
Member 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
Member Author

Updated. Thank you

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@profetia
Copy link
Member Author

r? clippy

@rustbot rustbot assigned samueltardieu and unassigned blyxyas Oct 21, 2025
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.

Could you also squash the commits please? The current separation makes it harder to read and review.

View changes since this review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Oct 23, 2025
@profetia profetia force-pushed the issue15714 branch 2 times, most recently from 0a176fc to 081f15f Compare October 23, 2025 21:32
@profetia
Copy link
Member Author

r? clippy

@rustbot rustbot assigned Jarcho and unassigned dswij Nov 25, 2025
@profetia
Copy link
Member Author

profetia commented Dec 7, 2025

r? clippy

@rustbot rustbot assigned Centri3 and unassigned Jarcho Dec 7, 2025
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Dec 18, 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
Member Author

Also closes #16258

// So, we have to check that `a` is not referenced anywhere (even outside of the `.map` closure!)
// before the call to `unwrap_or`.

let mut unwrap_visitor = UnwrapVisitor {
Copy link
Member

Choose a reason for hiding this comment

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

I think these two are simple enough that we can just use the for_each_expr helper. And, can we add a comment here?

Comment on lines +167 to +169
&& let Node::Pat(pat) = self.cx.tcx.hir_node(local_id)
&& let PatKind::Binding(_, local_id, ..) = pat.kind
Copy link
Member

Choose a reason for hiding this comment

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

What does this part fix? When will this not be a PatKind::Binding, and why?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure about this too.

Copy link
Member Author

Choose a reason for hiding this comment

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

If you look into the issues this PR is addressing, all the changes in map_unwrap_or.rs, wrongly showed as additions, are actually the implementation from option_map_unwrap_or.rs, which is renamed to this file now.

Copy link
Member Author

Choose a reason for hiding this comment

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

For this reason, I prefer to leave these implementation details as is, while just focusing reorganizing the map_unwrap_or and map_unwrap_or_else two lints in this PR.

type NestedFilter = nested_filter::All;
type Result = ControlFlow<()>;
fn visit_expr(&mut self, expr: &'tcx rustc_hir::Expr<'_>) -> ControlFlow<()> {
// If we haven't found a reference yet, check if this references
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// If we haven't found a reference yet, check if this references
// Check if this references

This more so implies that the previous UnwrapVisitor checks for references, not this code. I was a bit confused last review.

Copy link
Member

Choose a reason for hiding this comment

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

I think we just need more tests in general. To be specific, cases where it doesn't lint, like for when unwrap_arg is referenced. Same with the mutable borrows case.

Copy link
Member

Choose a reason for hiding this comment

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

Ookay, looking at it again, that's not all that's in this file. So +1 from me.

fn visit_expr(&mut self, expr: &'tcx rustc_hir::Expr<'_>) -> ControlFlow<()> {
// If we haven't found a reference yet, check if this references
// one of the locals that was moved in the `unwrap_or` argument.
// We are only interested in exprs that appear before the `unwrap_or` call.
Copy link
Member

Choose a reason for hiding this comment

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

We are only interested in exprs that appear before the unwrap_or call.

Why is that? Does the borrowck error not happen in that case?

@Centri3
Copy link
Member

Centri3 commented Jan 8, 2026

Ok, hadn't noticed, that's fair. I'll do one final look tomorrow and then probably merge 👍

Copy link
Member

Choose a reason for hiding this comment

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

Ookay, looking at it again, that's not all that's in this file. So +1 from me.

@Centri3
Copy link
Member

Centri3 commented Jan 11, 2026

cc @samueltardieu, this look good to you? You previously requested changes.

@samueltardieu
Copy link
Member

cc @samueltardieu, this look good to you? You previously requested changes.

Yes, my points have been addressed. I'll merge since you +1'ed.

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

Labels

None yet

Projects

None yet

8 participants