Skip to content

[manual_flatten]: Fix with nested Some or Ok pattern #14846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025

Conversation

a-yossy
Copy link
Contributor

@a-yossy a-yossy commented May 19, 2025

changelog: [manual_flatten]: fix with nested Some or Ok pattern
fixes #6776

@a-yossy a-yossy changed the title Fix [manual_flatten] with nested Some or Ok pattern [manual_flatten]: Fix with nested Some or Ok pattern May 19, 2025
@a-yossy a-yossy marked this pull request as ready for review May 19, 2025 09:25
@rustbot
Copy link
Collaborator

rustbot commented May 19, 2025

r? @Alexendoo

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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 19, 2025
@@ -39,9 +39,13 @@ pub(super) fn check<'tcx>(
&& msrv.meets(cx, msrvs::ITER_FLATTEN)
{
let if_let_type = if some_ctor { "Some" } else { "Ok" };
let has_nested_tuple_struct = contains_nested_tuple_struct(pats);
Copy link
Member

Choose a reason for hiding this comment

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

This would apply to other refutable patterns too so it can use https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/fn.is_refutable.html

e.g. if let Some((x, 1)) = y { ... }

Comment on lines 194 to 200
help: ...and remove the outer `Some` variant in the for loop
--> tests/ui/manual_flatten.rs:131:9
|
LL | / if let Some((_, Some(n))) = n {
LL | | println!("{}", n);
LL | | }
| |_________^
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 it'd be better to not lint these cases, it doesn't make it shorter or reduce the nesting level

@Alexendoo Alexendoo linked an issue May 24, 2025 that may be closed by this pull request
@a-yossy
Copy link
Contributor Author

a-yossy commented May 26, 2025

Thank you for your review.
I have implemented the suggested changes and would appreciate it if you could verify them. Please inform me if the modifications do not align with your intended outcome.

@a-yossy a-yossy requested a review from Alexendoo May 26, 2025 16:52
@Alexendoo
Copy link
Member

Yeah that's great thanks, if you could squash the commits then it looks good to go

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels May 26, 2025
@rustbot rustbot removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) has-merge-commits PR has merge commits, merge with caution. labels May 26, 2025
@a-yossy
Copy link
Contributor Author

a-yossy commented May 26, 2025

Thank you for your review.
I've squashed the commits. Please let me know if there's anything else.

Copy link
Member

@Alexendoo Alexendoo left a comment

Choose a reason for hiding this comment

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

Thanks!

@Alexendoo Alexendoo added this pull request to the merge queue May 26, 2025
Merged via the queue into rust-lang:master with commit 3927a61 May 26, 2025
11 checks passed
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.

manual_flatten ignores nested refutable pattern manual_flatten interaction with nested matches could better
4 participants