Skip to content

Commit

Permalink
Rollup merge of rust-lang#61342 - memoryruins:ellipsis_inclusive_rang…
Browse files Browse the repository at this point in the history
…e_patterns, r=Centril

Set ellipsis_inclusive_range_patterns lint to warn

Continuing rust-lang#54910, the `ellipsis_inclusive_range_patterns` lint is set to warn.

r? @Centril
  • Loading branch information
Centril authored May 30, 2019
2 parents c79244b + e18885e commit d1d35ce
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 32 deletions.
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,
});
}
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.

#![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() {
}

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

0 comments on commit d1d35ce

Please sign in to comment.