-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix: unnested_or_patterns
suggests wrongly in let
#14401
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one way to fix it up, but there might be a simpler one. By fixing the visitor in insert_necessary_parens()
to not remove parens (if any) on the outermost pattern, you get the same result without having to introduce PatternSource
. This could be something like (with minimal diffs to the existing visitor):
fn remove_all_parens(pat: &mut P<Pat>) {
#[derive(Default)]
struct Visitor {
is_inner: bool,
}
impl MutVisitor for Visitor {
fn visit_pat(&mut self, pat: &mut P<Pat>) {
let is_inner = mem::replace(&mut self.is_inner, true);
walk_pat(self, pat);
pat.kind = match &mut pat.kind {
Paren(i) if is_inner => mem::replace(&mut i.kind, Wild),
_ => return,
};
}
}
Visitor::default().visit_pat(pat);
}
The only difference in output with what you are proposing is that this wouldn't "fix" the outermost parens if the user chose to use them. For example, this would transform:
if let (0 | (1 | 2)) = …
into
if let (0 | 1 | 2) = …
whereas your change also drops the outermost parens. Even if dropping them is correct, this is not what the lint advertises, and this might be considered redundant with rustc's unused_parens
lint.
Good advice! Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, just a NIT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also looks good to me, just one small suggestion
Closes #9952
changelog: [
unnested_or_patterns
] fix wrong suggestion inlet