@@ -1285,10 +1285,29 @@ declare_lint! {
12851285 "`...` range patterns are deprecated"
12861286}
12871287
1288- declare_lint_pass ! ( EllipsisInclusiveRangePatterns => [ ELLIPSIS_INCLUSIVE_RANGE_PATTERNS ] ) ;
1288+ pub struct EllipsisInclusiveRangePatterns {
1289+ /// If `Some(_)`, suppress all subsequent pattern
1290+ /// warnings for better diagnostics.
1291+ node_id : Option < ast:: NodeId > ,
1292+ }
1293+
1294+ impl_lint_pass ! ( EllipsisInclusiveRangePatterns => [ ELLIPSIS_INCLUSIVE_RANGE_PATTERNS ] ) ;
1295+
1296+ impl EllipsisInclusiveRangePatterns {
1297+ pub fn new ( ) -> Self {
1298+ Self {
1299+ node_id : None ,
1300+ }
1301+ }
1302+ }
12891303
12901304impl EarlyLintPass for EllipsisInclusiveRangePatterns {
1291- fn check_pat ( & mut self , cx : & EarlyContext < ' _ > , pat : & ast:: Pat , visit_subpats : & mut bool ) {
1305+ fn check_pat ( & mut self , cx : & EarlyContext < ' _ > , pat : & ast:: Pat ) {
1306+ if self . node_id . is_some ( ) {
1307+ // Don't recursively warn about patterns inside range endpoints.
1308+ return
1309+ }
1310+
12921311 use self :: ast:: { PatKind , RangeEnd , RangeSyntax :: DotDotDot } ;
12931312
12941313 /// 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 {
13111330 let msg = "`...` range patterns are deprecated" ;
13121331 let suggestion = "use `..=` for an inclusive range" ;
13131332 if parenthesise {
1314- * visit_subpats = false ;
1333+ self . node_id = Some ( pat . id ) ;
13151334 let mut err = cx. struct_span_lint ( ELLIPSIS_INCLUSIVE_RANGE_PATTERNS , pat. span , msg) ;
13161335 err. span_suggestion (
13171336 pat. span ,
@@ -1332,6 +1351,14 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
13321351 } ;
13331352 }
13341353 }
1354+
1355+ fn check_pat_post ( & mut self , _cx : & EarlyContext < ' _ > , pat : & ast:: Pat ) {
1356+ if let Some ( node_id) = self . node_id {
1357+ if pat. id == node_id {
1358+ self . node_id = None
1359+ }
1360+ }
1361+ }
13351362}
13361363
13371364declare_lint ! {
0 commit comments