Skip to content
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

Set ellipsis_inclusive_range_patterns lint to warn #61342

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ declare_lint_pass!(

declare_lint! {
pub ELLIPSIS_INCLUSIVE_RANGE_PATTERNS,
Allow,
Warn,
"`...` range patterns are deprecated"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// run-pass
#![allow(dead_code, unreachable_patterns)]
#![allow(ellipsis_inclusive_range_patterns)]

struct Foo;

Expand All @@ -23,4 +24,17 @@ fn main() {
<Foo as HasNum>::NUM ... <Foo>::NUM => true,
_ => false,
});

assert!(match 2 {
Foo::NUM ..= 3 => true,
_ => false,
});
assert!(match 0 {
-1 ..= <Foo as HasNum>::NUM => true,
_ => false,
});
assert!(match 1 {
<Foo as HasNum>::NUM ..= <Foo>::NUM => true,
_ => false,
});
memoryruins marked this conversation as resolved.
Show resolved Hide resolved
}
6 changes: 6 additions & 0 deletions src/test/run-pass/binding/pat-ranges.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// run-pass
// Parsing of range patterns

#![allow(ellipsis_inclusive_range_patterns)]

const NUM1: i32 = 10;

mod m {
Expand All @@ -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 {}
}
2 changes: 2 additions & 0 deletions src/test/run-pass/inc-range-pat.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Test old and new syntax for inclusive range patterns.
memoryruins marked this conversation as resolved.
Show resolved Hide resolved

#![allow(ellipsis_inclusive_range_patterns)]

fn main() {
assert!(match 42 { 0 ... 100 => true, _ => false });
assert!(match 42 { 0 ..= 100 => true, _ => false });
Expand Down
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/mir/mir_build_match_comparisons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(dead_code)]
fn test1(x: i8) -> i32 {
match x {
1...10 => 0,
1..=10 => 0,
_ => 1,
}
}
Expand Down
28 changes: 25 additions & 3 deletions src/test/ui/lint/issue-54538-unused-parens-lint.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,14 +37,14 @@ fn main() {
}
memoryruins marked this conversation as resolved.
Show resolved Hide resolved

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
&_ => {}
}
}
52 changes: 44 additions & 8 deletions src/test/ui/lint/issue-54538-unused-parens-lint.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 9 additions & 9 deletions src/test/ui/match/match-range-fail-dominate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {}
_ => {}
};
Expand Down
14 changes: 7 additions & 7 deletions src/test/ui/match/match-range-fail-dominate.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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!
Expand All @@ -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!
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/nll/issue-57960.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(),
}
}
Expand Down