Skip to content

Commit b7adead

Browse files
committed
Add tests
1 parent 41d97c8 commit b7adead

File tree

6 files changed

+36
-16
lines changed

6 files changed

+36
-16
lines changed

tests/ui/or-patterns/bindings-runpass-2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ fn main() {
2626
assert_eq!(or_at(Err(7)), 207);
2727
assert_eq!(or_at(Err(8)), 8);
2828
assert_eq!(or_at(Err(20)), 220);
29+
assert_eq!(or_at(Err(34)), 134);
2930
assert_eq!(or_at(Err(50)), 500);
3031
}

tests/ui/or-patterns/inner-or-pat.or3.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/inner-or-pat.rs:38:54
2+
--> $DIR/inner-or-pat.rs:36:54
33
|
44
LL | match x {
55
| - this expression has type `&str`

tests/ui/or-patterns/inner-or-pat.or4.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0408]: variable `x` is not bound in all patterns
2-
--> $DIR/inner-or-pat.rs:53:37
2+
--> $DIR/inner-or-pat.rs:51:37
33
|
44
LL | (x @ "red" | (x @ "blue" | "red")) => {
55
| - ^^^^^ pattern doesn't bind `x`

tests/ui/or-patterns/inner-or-pat.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
//@ revisions: or1 or2 or3 or4 or5
1+
//@ revisions: or1 or3 or4
22
//@ [or1] run-pass
3-
//@ [or2] run-pass
4-
//@ [or5] run-pass
53

64
#![allow(unreachable_patterns)]
75
#![allow(unused_variables)]
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
//@ check-pass
1+
//@ run-pass
22

33
#![deny(unreachable_patterns)]
44

55
fn main() {
6-
match (3,42) {
7-
(a,_) | (_,a) if a > 10 => {println!("{}", a)}
8-
_ => ()
6+
match (3, 42) {
7+
(a, _) | (_, a) if a > 10 => {}
8+
_ => unreachable!(),
99
}
1010

11-
match Some((3,42)) {
12-
Some((a, _)) | Some((_, a)) if a > 10 => {println!("{}", a)}
13-
_ => ()
14-
11+
match Some((3, 42)) {
12+
Some((a, _)) | Some((_, a)) if a > 10 => {}
13+
_ => unreachable!(),
1514
}
1615

17-
match Some((3,42)) {
18-
Some((a, _) | (_, a)) if a > 10 => {println!("{}", a)}
19-
_ => ()
16+
match Some((3, 42)) {
17+
Some((a, _) | (_, a)) if a > 10 => {}
18+
_ => unreachable!(),
2019
}
2120
}

tests/ui/or-patterns/search-via-bindings.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ fn search_old_style(target: (bool, bool, bool)) -> u32 {
4242
}
4343
}
4444

45+
// Check that a dummy or-pattern also leads to running the guard multiple times.
46+
fn search_with_dummy(target: (bool, bool)) -> u32 {
47+
let x = ((false, true), (false, true), ());
48+
let mut guard_count = 0;
49+
match x {
50+
((a, _) | (_, a), (b, _) | (_, b), _ | _)
51+
if {
52+
guard_count += 1;
53+
(a, b) == target
54+
} =>
55+
{
56+
guard_count
57+
}
58+
_ => unreachable!(),
59+
}
60+
}
61+
4562
fn main() {
4663
assert_eq!(search((false, false, false)), 1);
4764
assert_eq!(search((false, false, true)), 2);
@@ -60,4 +77,9 @@ fn main() {
6077
assert_eq!(search_old_style((true, false, true)), 6);
6178
assert_eq!(search_old_style((true, true, false)), 7);
6279
assert_eq!(search_old_style((true, true, true)), 8);
80+
81+
assert_eq!(search_with_dummy((false, false)), 1);
82+
assert_eq!(search_with_dummy((false, true)), 3);
83+
assert_eq!(search_with_dummy((true, false)), 5);
84+
assert_eq!(search_with_dummy((true, true)), 7);
6385
}

0 commit comments

Comments
 (0)