-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Remove visit_subpats
parameter from check_pat
#60152
Conversation
|
||
impl_lint_pass!(EllipsisInclusiveRangePatterns => [ELLIPSIS_INCLUSIVE_RANGE_PATTERNS]); | ||
|
||
impl EllipsisInclusiveRangePatterns { |
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.
You can #[derive(Default)]
for this instead.
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.
I chose it b/c of consistency, there's new
on other linters, e.g. https://github.com/rust-lang/rust/blob/5160955b96636db3b3b70a348c53454e73473538/src/librustc_lint/builtin.rs#L552 and https://github.com/rust-lang/rust/blob/5160955b96636db3b3b70a348c53454e73473538/src/librustc_lint/lib.rs#L99
#[derive(Default)]
would give me default
method
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.
@stepnivlk To achieve semantic compression, it seems preferable to use #[derive(Default)]
wherever possible for these lints. Could you file an issue for converting all places in a different PR?
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 looks good to me! Just a couple of tiny comments about formatting (and adding a couple of comments).
src/librustc_lint/builtin.rs
Outdated
|
||
impl EarlyLintPass for EllipsisInclusiveRangePatterns { | ||
fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &ast::Pat, visit_subpats: &mut bool) { | ||
fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &ast::Pat) { | ||
if let Some(_node_id) = self.node_id { return } |
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.
if let Some(_node_id) = self.node_id { return } | |
if self.node_id.is_some() { | |
// Don't recursively warn about patterns inside range endpoints. | |
return | |
} |
@@ -1286,10 +1286,24 @@ declare_lint! { | |||
"`...` range patterns are deprecated" | |||
} | |||
|
|||
declare_lint_pass!(EllipsisInclusiveRangePatterns => [ELLIPSIS_INCLUSIVE_RANGE_PATTERNS]); | |||
pub struct EllipsisInclusiveRangePatterns { | |||
node_id: Option<ast::NodeId>, |
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.
node_id: Option<ast::NodeId>, | |
/// If `Some(_)`, suppress all subsequent pattern | |
/// warnings for better diagnostics. | |
node_id: Option<ast::NodeId>, |
src/librustc_lint/builtin.rs
Outdated
|
||
fn check_pat_post(&mut self, _cx: &EarlyContext<'_>, pat: &ast::Pat) { | ||
if let Some(node_id) = self.node_id { | ||
if pat.id == node_id { self.node_id = None } |
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.
if pat.id == node_id { self.node_id = None } | |
if pat.id == node_id { | |
self.node_id = None; | |
} |
(Blocks should be on new lines.)
…usiveRangePatterns
@stepnivlk: thanks! @bors r+ |
📌 Commit 1dc13b5 has been approved by |
☀️ Test successful - checks-travis, status-appveyor |
📣 Toolstate changed by #60152! Tested on commit fe0a415. 💔 clippy-driver on windows: test-fail → build-fail (cc @Manishearth @llogiq @mcarton @oli-obk @phansch, @rust-lang/infra). |
Tested on commit rust-lang/rust@fe0a415. Direct link to PR: <rust-lang/rust#60152> 💔 clippy-driver on windows: test-fail → build-fail (cc @Manishearth @llogiq @mcarton @oli-obk @phansch, @rust-lang/infra). 💔 clippy-driver on linux: test-fail → build-fail (cc @Manishearth @llogiq @mcarton @oli-obk @phansch, @rust-lang/infra). 💔 rls on windows: test-fail → build-fail (cc @Xanewok, @rust-lang/infra). 💔 rls on linux: test-fail → build-fail (cc @Xanewok, @rust-lang/infra).
The core idea is to keep track of current ID directly in
EllipsisInclusiveRangePatterns
struct and early return incheck_pat
based on it.Fixes #60043.
r? @varkor