mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Add some tests
This commit is contained in:
parent
e6aa96246f
commit
00ccadf43f
@ -6,35 +6,63 @@
|
||||
// We wrap patterns in a tuple because top-level or-patterns are special-cased for now.
|
||||
fn main() {
|
||||
// Get the fatal error out of the way
|
||||
match (0u8,) {
|
||||
match (0,) {
|
||||
(0 | _,) => {}
|
||||
//~^ ERROR or-patterns are not fully implemented yet
|
||||
}
|
||||
|
||||
match (0u8,) {
|
||||
match (0,) {
|
||||
(1 | 2,) => {}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
match (0u8,) {
|
||||
(1 | 1,) => {} // FIXME(or_patterns): redundancy not detected for now.
|
||||
_ => {}
|
||||
}
|
||||
match (0u8, 0u8) {
|
||||
match (0, 0) {
|
||||
(1 | 2, 3 | 4) => {}
|
||||
(1, 2) => {}
|
||||
(2, 1) => {}
|
||||
(3, 1) => {}
|
||||
_ => {}
|
||||
}
|
||||
match (Some(0u8),) {
|
||||
(None | Some(0 | 1),) => {}
|
||||
(Some(2..=255),) => {}
|
||||
}
|
||||
match ((0u8,),) {
|
||||
match ((0,),) {
|
||||
((0 | 1,) | (2 | 3,),) => {},
|
||||
((_,),) => {},
|
||||
}
|
||||
match (&[0u8][..],) {
|
||||
([] | [0 | 1..=255] | [_, ..],) => {},
|
||||
}
|
||||
|
||||
match ((0, 0),) {
|
||||
((0, 0) | (0, 1),) => {}
|
||||
_ => {}
|
||||
}
|
||||
match ((0, 0),) {
|
||||
((0, 0) | (1, 0),) => {}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// FIXME(or_patterns): Redundancies not detected for now.
|
||||
match (0,) {
|
||||
(1 | 1,) => {}
|
||||
_ => {}
|
||||
}
|
||||
match [0; 2] {
|
||||
[0 | 0, 0 | 0] => {}
|
||||
_ => {}
|
||||
}
|
||||
match &[][..] {
|
||||
[0] => {}
|
||||
[0, _] => {}
|
||||
[0, _, _] => {}
|
||||
[1, ..] => {}
|
||||
[1 | 2, ..] => {}
|
||||
_ => {}
|
||||
}
|
||||
match Some(0) {
|
||||
Some(0) => {}
|
||||
Some(0 | 1) => {}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
58
src/test/ui/pattern/usefulness/top-level-alternation.rs
Normal file
58
src/test/ui/pattern/usefulness/top-level-alternation.rs
Normal file
@ -0,0 +1,58 @@
|
||||
#![deny(unreachable_patterns)]
|
||||
|
||||
fn main() {
|
||||
while let 0..=2 | 1 = 0 {} //~ ERROR unreachable pattern
|
||||
if let 0..=2 | 1 = 0 {} //~ WARN irrefutable if-let pattern
|
||||
// this one ^ is incorrect
|
||||
|
||||
match 0u8 {
|
||||
0
|
||||
| 0 => {} //~ ERROR unreachable pattern
|
||||
_ => {}
|
||||
}
|
||||
match Some(0u8) {
|
||||
Some(0)
|
||||
| Some(0) => {} //~ ERROR unreachable pattern
|
||||
_ => {}
|
||||
}
|
||||
match (0u8, 0u8) {
|
||||
(0, _) | (_, 0) => {}
|
||||
(0, 0) => {} //~ ERROR unreachable pattern
|
||||
(1, 1) => {}
|
||||
_ => {}
|
||||
}
|
||||
match (0u8, 0u8) {
|
||||
(0, 1) | (2, 3) => {}
|
||||
(0, 3) => {}
|
||||
(2, 1) => {}
|
||||
_ => {}
|
||||
}
|
||||
match (0u8, 0u8) {
|
||||
(_, 0) | (_, 1) => {}
|
||||
_ => {}
|
||||
}
|
||||
match (0u8, 0u8) {
|
||||
(0, _) | (1, _) => {}
|
||||
_ => {}
|
||||
}
|
||||
match Some(0u8) {
|
||||
None | Some(_) => {}
|
||||
_ => {} //~ ERROR unreachable pattern
|
||||
}
|
||||
match Some(0u8) {
|
||||
None | Some(_) => {}
|
||||
Some(_) => {} //~ ERROR unreachable pattern
|
||||
None => {} //~ ERROR unreachable pattern
|
||||
}
|
||||
match Some(0u8) {
|
||||
Some(_) => {}
|
||||
None => {}
|
||||
None //~ ERROR unreachable pattern
|
||||
| Some(_) => {} //~ ERROR unreachable pattern
|
||||
}
|
||||
match 0u8 {
|
||||
1 | 2 => {},
|
||||
1..=2 => {}, //~ ERROR unreachable pattern
|
||||
_ => {},
|
||||
}
|
||||
}
|
76
src/test/ui/pattern/usefulness/top-level-alternation.stderr
Normal file
76
src/test/ui/pattern/usefulness/top-level-alternation.stderr
Normal file
@ -0,0 +1,76 @@
|
||||
error: unreachable pattern
|
||||
--> $DIR/top-level-alternation.rs:4:23
|
||||
|
|
||||
LL | while let 0..=2 | 1 = 0 {}
|
||||
| ^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/top-level-alternation.rs:1:9
|
||||
|
|
||||
LL | #![deny(unreachable_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: irrefutable if-let pattern
|
||||
--> $DIR/top-level-alternation.rs:5:20
|
||||
|
|
||||
LL | if let 0..=2 | 1 = 0 {}
|
||||
| ^
|
||||
|
|
||||
= note: `#[warn(irrefutable_let_patterns)]` on by default
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/top-level-alternation.rs:10:15
|
||||
|
|
||||
LL | | 0 => {}
|
||||
| ^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/top-level-alternation.rs:15:15
|
||||
|
|
||||
LL | | Some(0) => {}
|
||||
| ^^^^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/top-level-alternation.rs:20:9
|
||||
|
|
||||
LL | (0, 0) => {}
|
||||
| ^^^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/top-level-alternation.rs:40:9
|
||||
|
|
||||
LL | _ => {}
|
||||
| ^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/top-level-alternation.rs:44:9
|
||||
|
|
||||
LL | Some(_) => {}
|
||||
| ^^^^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/top-level-alternation.rs:45:9
|
||||
|
|
||||
LL | None => {}
|
||||
| ^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/top-level-alternation.rs:50:9
|
||||
|
|
||||
LL | None
|
||||
| ^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/top-level-alternation.rs:51:15
|
||||
|
|
||||
LL | | Some(_) => {}
|
||||
| ^^^^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/top-level-alternation.rs:55:9
|
||||
|
|
||||
LL | 1..=2 => {},
|
||||
| ^^^^^
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user