diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index d184c671bbaf8..434a1498a1c93 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1275,7 +1275,7 @@ declare_lint_pass!( declare_lint! { pub ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, - Allow, + Warn, "`...` range patterns are deprecated" } diff --git a/src/test/run-pass/associated-consts/associated-const-range-match-patterns.rs b/src/test/run-pass/associated-consts/associated-const-range-match-patterns.rs index 4801369cfd1a8..5276869a702ee 100644 --- a/src/test/run-pass/associated-consts/associated-const-range-match-patterns.rs +++ b/src/test/run-pass/associated-consts/associated-const-range-match-patterns.rs @@ -1,5 +1,6 @@ // run-pass #![allow(dead_code, unreachable_patterns)] +#![allow(ellipsis_inclusive_range_patterns)] struct Foo; @@ -23,4 +24,17 @@ fn main() { ::NUM ... ::NUM => true, _ => false, }); + + assert!(match 2 { + Foo::NUM ..= 3 => true, + _ => false, + }); + assert!(match 0 { + -1 ..= ::NUM => true, + _ => false, + }); + assert!(match 1 { + ::NUM ..= ::NUM => true, + _ => false, + }); } diff --git a/src/test/run-pass/binding/pat-ranges.rs b/src/test/run-pass/binding/pat-ranges.rs index b3729a79615a6..19b3045784f86 100644 --- a/src/test/run-pass/binding/pat-ranges.rs +++ b/src/test/run-pass/binding/pat-ranges.rs @@ -1,6 +1,8 @@ // run-pass // Parsing of range patterns +#![allow(ellipsis_inclusive_range_patterns)] + const NUM1: i32 = 10; mod m { @@ -11,4 +13,8 @@ fn main() { if let NUM1 ... m::NUM2 = 10 {} else { panic!() } if let ::NUM1 ... ::m::NUM2 = 11 {} else { panic!() } if let -13 ... -10 = 12 { panic!() } else {} + + if let NUM1 ..= m::NUM2 = 10 {} else { panic!() } + if let ::NUM1 ..= ::m::NUM2 = 11 {} else { panic!() } + if let -13 ..= -10 = 12 { panic!() } else {} } diff --git a/src/test/run-pass/inc-range-pat.rs b/src/test/run-pass/inc-range-pat.rs index 6bf857a11f816..a648ff17492ee 100644 --- a/src/test/run-pass/inc-range-pat.rs +++ b/src/test/run-pass/inc-range-pat.rs @@ -1,5 +1,7 @@ // Test old and new syntax for inclusive range patterns. +#![allow(ellipsis_inclusive_range_patterns)] + fn main() { assert!(match 42 { 0 ... 100 => true, _ => false }); assert!(match 42 { 0 ..= 100 => true, _ => false }); diff --git a/src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.rs b/src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.rs index 2470e37e1820b..dee7f25d7bb3a 100644 --- a/src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.rs +++ b/src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.rs @@ -1,5 +1,6 @@ // run-pass #![allow(illegal_floating_point_literal_pattern)] // FIXME #41620 +#![allow(ellipsis_inclusive_range_patterns)] // regression test for the model lexer handling the DOTDOTDOT syntax (#15877) diff --git a/src/test/run-pass/mir/mir_build_match_comparisons.rs b/src/test/run-pass/mir/mir_build_match_comparisons.rs index 8913009f69156..04570055763a9 100644 --- a/src/test/run-pass/mir/mir_build_match_comparisons.rs +++ b/src/test/run-pass/mir/mir_build_match_comparisons.rs @@ -2,7 +2,7 @@ #![allow(dead_code)] fn test1(x: i8) -> i32 { match x { - 1...10 => 0, + 1..=10 => 0, _ => 1, } } diff --git a/src/test/ui/lint/issue-54538-unused-parens-lint.rs b/src/test/ui/lint/issue-54538-unused-parens-lint.rs index 6ca53816e3c6b..3a52996195c0d 100644 --- a/src/test/ui/lint/issue-54538-unused-parens-lint.rs +++ b/src/test/ui/lint/issue-54538-unused-parens-lint.rs @@ -1,10 +1,32 @@ // compile-pass +#![allow(ellipsis_inclusive_range_patterns)] #![allow(unreachable_patterns)] #![allow(unused_variables)] #![warn(unused_parens)] fn main() { + match 1 { + (_) => {} //~ WARNING: unnecessary parentheses around pattern + (y) => {} //~ WARNING: unnecessary parentheses around pattern + (ref r) => {} //~ WARNING: unnecessary parentheses around pattern + (e @ 1...2) => {} //~ WARNING: unnecessary parentheses around outer pattern + (1...2) => {} // Non ambiguous range pattern should not warn + e @ (3...4) => {} // Non ambiguous range pattern should not warn + } + + match &1 { + (e @ &(1...2)) => {} //~ WARNING: unnecessary parentheses around outer pattern + &(_) => {} //~ WARNING: unnecessary parentheses around pattern + e @ &(1...2) => {} // Ambiguous range pattern should not warn + &(1...2) => {} // Ambiguous range pattern should not warn + } + + match &1 { + e @ &(1...2) | e @ &(3...4) => {} // Complex ambiguous pattern should not warn + &_ => {} + } + match 1 { (_) => {} //~ WARNING: unnecessary parentheses around pattern (y) => {} //~ WARNING: unnecessary parentheses around pattern @@ -15,14 +37,14 @@ fn main() { } match &1 { - (e @ &(1...2)) => {} //~ WARNING: unnecessary parentheses around outer pattern + (e @ &(1..=2)) => {} //~ WARNING: unnecessary parentheses around outer pattern &(_) => {} //~ WARNING: unnecessary parentheses around pattern - e @ &(1...2) => {} // Ambiguous range pattern should not warn + e @ &(1..=2) => {} // Ambiguous range pattern should not warn &(1..=2) => {} // Ambiguous range pattern should not warn } match &1 { - e @ &(1...2) | e @ &(3..=4) => {} // Complex ambiguous pattern should not warn + e @ &(1..=2) | e @ &(3..=4) => {} // Complex ambiguous pattern should not warn &_ => {} } } diff --git a/src/test/ui/lint/issue-54538-unused-parens-lint.stderr b/src/test/ui/lint/issue-54538-unused-parens-lint.stderr index 3cf321b072f40..3b312198952a5 100644 --- a/src/test/ui/lint/issue-54538-unused-parens-lint.stderr +++ b/src/test/ui/lint/issue-54538-unused-parens-lint.stderr @@ -1,41 +1,77 @@ warning: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:9:9 + --> $DIR/issue-54538-unused-parens-lint.rs:10:9 | LL | (_) => {} | ^^^ help: remove these parentheses | note: lint level defined here - --> $DIR/issue-54538-unused-parens-lint.rs:5:9 + --> $DIR/issue-54538-unused-parens-lint.rs:6:9 | LL | #![warn(unused_parens)] | ^^^^^^^^^^^^^ warning: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:10:9 + --> $DIR/issue-54538-unused-parens-lint.rs:11:9 | LL | (y) => {} | ^^^ help: remove these parentheses warning: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:11:9 + --> $DIR/issue-54538-unused-parens-lint.rs:12:9 | LL | (ref r) => {} | ^^^^^^^ help: remove these parentheses warning: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:12:9 + --> $DIR/issue-54538-unused-parens-lint.rs:13:9 | -LL | (e @ 1..=2) => {} +LL | (e @ 1...2) => {} | ^^^^^^^^^^^ help: remove these parentheses warning: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:18:9 + --> $DIR/issue-54538-unused-parens-lint.rs:19:9 | LL | (e @ &(1...2)) => {} | ^^^^^^^^^^^^^^ help: remove these parentheses warning: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:19:10 + --> $DIR/issue-54538-unused-parens-lint.rs:20:10 + | +LL | &(_) => {} + | ^^^ help: remove these parentheses + +warning: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:31:9 + | +LL | (_) => {} + | ^^^ help: remove these parentheses + +warning: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:32:9 + | +LL | (y) => {} + | ^^^ help: remove these parentheses + +warning: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:33:9 + | +LL | (ref r) => {} + | ^^^^^^^ help: remove these parentheses + +warning: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:34:9 + | +LL | (e @ 1..=2) => {} + | ^^^^^^^^^^^ help: remove these parentheses + +warning: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:40:9 + | +LL | (e @ &(1..=2)) => {} + | ^^^^^^^^^^^^^^ help: remove these parentheses + +warning: unnecessary parentheses around pattern + --> $DIR/issue-54538-unused-parens-lint.rs:41:10 | LL | &(_) => {} | ^^^ help: remove these parentheses diff --git a/src/test/ui/match/match-range-fail-dominate.rs b/src/test/ui/match/match-range-fail-dominate.rs index 99069183e4eda..a0cc773d20edd 100644 --- a/src/test/ui/match/match-range-fail-dominate.rs +++ b/src/test/ui/match/match-range-fail-dominate.rs @@ -8,31 +8,31 @@ fn main() { match 5 { - 1 ... 10 => { } - 5 ... 6 => { } + 1 ..= 10 => { } + 5 ..= 6 => { } _ => {} }; match 5 { - 3 ... 6 => { } - 4 ... 6 => { } + 3 ..= 6 => { } + 4 ..= 6 => { } _ => {} }; match 5 { - 4 ... 6 => { } - 4 ... 6 => { } + 4 ..= 6 => { } + 4 ..= 6 => { } _ => {} }; match 'c' { - 'A' ... 'z' => {} - 'a' ... 'z' => {} + 'A' ..= 'z' => {} + 'a' ..= 'z' => {} _ => {} }; match 1.0f64 { - 0.01f64 ... 6.5f64 => {} + 0.01f64 ..= 6.5f64 => {} 0.02f64 => {} _ => {} }; diff --git a/src/test/ui/match/match-range-fail-dominate.stderr b/src/test/ui/match/match-range-fail-dominate.stderr index 0f5ab7fff3840..f481e56c85e56 100644 --- a/src/test/ui/match/match-range-fail-dominate.stderr +++ b/src/test/ui/match/match-range-fail-dominate.stderr @@ -1,7 +1,7 @@ error: unreachable pattern --> $DIR/match-range-fail-dominate.rs:12:7 | -LL | 5 ... 6 => { } +LL | 5 ..= 6 => { } | ^^^^^^^ | note: lint level defined here @@ -13,25 +13,25 @@ LL | #![deny(unreachable_patterns)] error: unreachable pattern --> $DIR/match-range-fail-dominate.rs:18:7 | -LL | 4 ... 6 => { } +LL | 4 ..= 6 => { } | ^^^^^^^ error: unreachable pattern --> $DIR/match-range-fail-dominate.rs:24:7 | -LL | 4 ... 6 => { } +LL | 4 ..= 6 => { } | ^^^^^^^ error: unreachable pattern --> $DIR/match-range-fail-dominate.rs:30:7 | -LL | 'a' ... 'z' => {} +LL | 'a' ..= 'z' => {} | ^^^^^^^^^^^ warning: floating-point types cannot be used in patterns --> $DIR/match-range-fail-dominate.rs:35:7 | -LL | 0.01f64 ... 6.5f64 => {} +LL | 0.01f64 ..= 6.5f64 => {} | ^^^^^^^ | = note: #[warn(illegal_floating_point_literal_pattern)] on by default @@ -41,7 +41,7 @@ LL | 0.01f64 ... 6.5f64 => {} warning: floating-point types cannot be used in patterns --> $DIR/match-range-fail-dominate.rs:35:19 | -LL | 0.01f64 ... 6.5f64 => {} +LL | 0.01f64 ..= 6.5f64 => {} | ^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -65,7 +65,7 @@ LL | 0.02f64 => {} warning: floating-point types cannot be used in patterns --> $DIR/match-range-fail-dominate.rs:35:7 | -LL | 0.01f64 ... 6.5f64 => {} +LL | 0.01f64 ..= 6.5f64 => {} | ^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/src/test/ui/nll/issue-57960.rs b/src/test/ui/nll/issue-57960.rs index 0b52e46c45989..1399694a79b6a 100644 --- a/src/test/ui/nll/issue-57960.rs +++ b/src/test/ui/nll/issue-57960.rs @@ -27,9 +27,9 @@ impl Range for ThreeDigits { fn digits(x: u8) -> u32 { match x { - OneDigit::FIRST...OneDigit::LAST => 1, - TwoDigits::FIRST...TwoDigits::LAST => 2, - ThreeDigits::FIRST...ThreeDigits::LAST => 3, + OneDigit::FIRST..=OneDigit::LAST => 1, + TwoDigits::FIRST..=TwoDigits::LAST => 2, + ThreeDigits::FIRST..=ThreeDigits::LAST => 3, _ => unreachable!(), } }