@@ -1285,10 +1285,29 @@ declare_lint! {
1285
1285
"`...` range patterns are deprecated"
1286
1286
}
1287
1287
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
+ }
1289
1303
1290
1304
impl 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
+
1292
1311
use self :: ast:: { PatKind , RangeEnd , RangeSyntax :: DotDotDot } ;
1293
1312
1294
1313
/// 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 {
1311
1330
let msg = "`...` range patterns are deprecated" ;
1312
1331
let suggestion = "use `..=` for an inclusive range" ;
1313
1332
if parenthesise {
1314
- * visit_subpats = false ;
1333
+ self . node_id = Some ( pat . id ) ;
1315
1334
let mut err = cx. struct_span_lint ( ELLIPSIS_INCLUSIVE_RANGE_PATTERNS , pat. span , msg) ;
1316
1335
err. span_suggestion (
1317
1336
pat. span ,
@@ -1332,6 +1351,14 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
1332
1351
} ;
1333
1352
}
1334
1353
}
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
+ }
1335
1362
}
1336
1363
1337
1364
declare_lint ! {
0 commit comments