-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1285,10 +1285,29 @@ declare_lint! { | |
"`...` range patterns are deprecated" | ||
} | ||
|
||
declare_lint_pass!(EllipsisInclusiveRangePatterns => [ELLIPSIS_INCLUSIVE_RANGE_PATTERNS]); | ||
pub struct EllipsisInclusiveRangePatterns { | ||
/// If `Some(_)`, suppress all subsequent pattern | ||
/// warnings for better diagnostics. | ||
node_id: Option<ast::NodeId>, | ||
} | ||
|
||
impl_lint_pass!(EllipsisInclusiveRangePatterns => [ELLIPSIS_INCLUSIVE_RANGE_PATTERNS]); | ||
|
||
impl EllipsisInclusiveRangePatterns { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I chose it b/c of consistency, there's
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stepnivlk To achieve semantic compression, it seems preferable to use |
||
pub fn new() -> Self { | ||
Self { | ||
node_id: None, | ||
} | ||
} | ||
} | ||
|
||
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 self.node_id.is_some() { | ||
// Don't recursively warn about patterns inside range endpoints. | ||
return | ||
} | ||
|
||
use self::ast::{PatKind, RangeEnd, RangeSyntax::DotDotDot}; | ||
|
||
/// If `pat` is a `...` pattern, return the start and end of the range, as well as the span | ||
|
@@ -1311,7 +1330,7 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns { | |
let msg = "`...` range patterns are deprecated"; | ||
let suggestion = "use `..=` for an inclusive range"; | ||
if parenthesise { | ||
*visit_subpats = false; | ||
self.node_id = Some(pat.id); | ||
let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, pat.span, msg); | ||
err.span_suggestion( | ||
pat.span, | ||
|
@@ -1332,6 +1351,14 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns { | |
}; | ||
} | ||
} | ||
|
||
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 | ||
} | ||
} | ||
} | ||
} | ||
|
||
declare_lint! { | ||
|
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.