-
Notifications
You must be signed in to change notification settings - Fork 1.8k
WIP: New lint: duplicate_match_guards
#14986
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
base: master
Are you sure you want to change the base?
Conversation
bd9de96
to
c7f0188
Compare
c7f0188
to
71c4b42
Compare
8bd7cbe
to
a86397c
Compare
duplicate_match_guard
duplicate_match_guards
fab6b13
to
1a5e31b
Compare
1a5e31b
to
d6e58a9
Compare
}; | ||
|
||
if let ExprKind::If(cond, then, None) = arm_body_expr.kind | ||
&& eq_expr_value(cx, guard, cond.peel_drop_temps()) |
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.
Since the lint is directed at copy-paste errors, maybe we should make this stricter, and make sure that the expr are "syntactically" equal, and don't just evaluate to the result.
} | ||
declare_lint_pass!(DuplicateMatchGuards => [DUPLICATE_MATCH_GUARDS]); | ||
|
||
impl<'tcx> LateLintPass<'tcx> for DuplicateMatchGuards { |
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.
Now that I think of it, this lint doesn't really type information, so it could be made early-pass I think?
they are not really necessary, since the match body already has its own
This reverts commit 1b44da7. it can be seen that things like comments are not included in this reduced span
NB: this doesn't suggest removing the inner body's curlies since there are no outer ones
required by the naming guidelines
previously, we suggested removing: - everything from the start of `arm_body_expr` to the start of `then` - and everything from the end of `then` to the end of `arm_body_expr` but that should be the same as just replacing `arm_body_expr` with `then` we seem to get some more lines with trailing spaces, but that's probably not that big of a deal...
d6e58a9
to
3e4ace9
Compare
Fixes #14971
WIP because:
eq_expr_value
takes care of impure function calls?changelog: new lint: [
duplicate_match_guards
]