Add tests
This commit is contained in:
parent
5639c21fb3
commit
6b84d7566e
10 changed files with 250 additions and 16 deletions
|
@ -26,5 +26,6 @@ fn main() {
|
|||
assert_eq!(or_at(Err(7)), 207);
|
||||
assert_eq!(or_at(Err(8)), 8);
|
||||
assert_eq!(or_at(Err(20)), 220);
|
||||
assert_eq!(or_at(Err(34)), 134);
|
||||
assert_eq!(or_at(Err(50)), 500);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/inner-or-pat.rs:38:54
|
||||
--> $DIR/inner-or-pat.rs:36:54
|
||||
|
|
||||
LL | match x {
|
||||
| - this expression has type `&str`
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error[E0408]: variable `x` is not bound in all patterns
|
||||
--> $DIR/inner-or-pat.rs:53:37
|
||||
--> $DIR/inner-or-pat.rs:51:37
|
||||
|
|
||||
LL | (x @ "red" | (x @ "blue" | "red")) => {
|
||||
| - ^^^^^ pattern doesn't bind `x`
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
//@ revisions: or1 or2 or3 or4 or5
|
||||
//@ revisions: or1 or3 or4
|
||||
//@ [or1] run-pass
|
||||
//@ [or2] run-pass
|
||||
//@ [or5] run-pass
|
||||
|
||||
#![allow(unreachable_patterns)]
|
||||
#![allow(unused_variables)]
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
//@ check-pass
|
||||
//@ run-pass
|
||||
|
||||
#![deny(unreachable_patterns)]
|
||||
|
||||
fn main() {
|
||||
match (3,42) {
|
||||
(a,_) | (_,a) if a > 10 => {println!("{}", a)}
|
||||
_ => ()
|
||||
match (3, 42) {
|
||||
(a, _) | (_, a) if a > 10 => {}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
match Some((3,42)) {
|
||||
Some((a, _)) | Some((_, a)) if a > 10 => {println!("{}", a)}
|
||||
_ => ()
|
||||
|
||||
match Some((3, 42)) {
|
||||
Some((a, _)) | Some((_, a)) if a > 10 => {}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
match Some((3,42)) {
|
||||
Some((a, _) | (_, a)) if a > 10 => {println!("{}", a)}
|
||||
_ => ()
|
||||
match Some((3, 42)) {
|
||||
Some((a, _) | (_, a)) if a > 10 => {}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,23 @@ fn search_old_style(target: (bool, bool, bool)) -> u32 {
|
|||
}
|
||||
}
|
||||
|
||||
// Check that a dummy or-pattern also leads to running the guard multiple times.
|
||||
fn search_with_dummy(target: (bool, bool)) -> u32 {
|
||||
let x = ((false, true), (false, true), ());
|
||||
let mut guard_count = 0;
|
||||
match x {
|
||||
((a, _) | (_, a), (b, _) | (_, b), _ | _)
|
||||
if {
|
||||
guard_count += 1;
|
||||
(a, b) == target
|
||||
} =>
|
||||
{
|
||||
guard_count
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(search((false, false, false)), 1);
|
||||
assert_eq!(search((false, false, true)), 2);
|
||||
|
@ -60,4 +77,9 @@ fn main() {
|
|||
assert_eq!(search_old_style((true, false, true)), 6);
|
||||
assert_eq!(search_old_style((true, true, false)), 7);
|
||||
assert_eq!(search_old_style((true, true, true)), 8);
|
||||
|
||||
assert_eq!(search_with_dummy((false, false)), 1);
|
||||
assert_eq!(search_with_dummy((false, true)), 3);
|
||||
assert_eq!(search_with_dummy((true, false)), 5);
|
||||
assert_eq!(search_with_dummy((true, true)), 7);
|
||||
}
|
||||
|
|
11
tests/ui/or-patterns/simplification_subtleties.rs
Normal file
11
tests/ui/or-patterns/simplification_subtleties.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
//@ run-pass
|
||||
|
||||
#[allow(unreachable_patterns)]
|
||||
fn main() {
|
||||
// Test that we don't naively sort the two `2`s together and confuse the failure paths.
|
||||
match (1, true) {
|
||||
(1 | 2, false | false) => unreachable!(),
|
||||
(2, _) => unreachable!(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue