Add tests to ensure that let_chains works with if_let_guard
This commit is contained in:
parent
5e57faa78a
commit
f491a9f601
@ -1,6 +1,6 @@
|
|||||||
// check-pass
|
// check-pass
|
||||||
|
|
||||||
#![feature(let_chains)]
|
#![feature(if_let_guard, let_chains)]
|
||||||
|
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
@ -16,6 +16,16 @@ fn main() {
|
|||||||
&& let None = local_start {
|
&& let None = local_start {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match opt {
|
||||||
|
Some(ref first) if let second = first && let _third = second => {},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
match opt {
|
||||||
|
Some(ref first) if let Range { start: local_start, end: _ } = first
|
||||||
|
&& let None = local_start => {},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
while let first = &opt && let Some(ref second) = first && let None = second.start {
|
while let first = &opt && let Some(ref second) = first && let None = second.start {
|
||||||
}
|
}
|
||||||
while let Some(ref first) = opt && let second = first && let _third = second {
|
while let Some(ref first) = opt && let second = first && let _third = second {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// run-pass
|
// run-pass
|
||||||
|
|
||||||
#![feature(let_chains)]
|
#![feature(if_let_guard, let_chains)]
|
||||||
|
|
||||||
fn check_if_let(opt: Option<Option<Option<i32>>>, value: i32) -> bool {
|
fn check_if_let(opt: Option<Option<Option<i32>>>, value: i32) -> bool {
|
||||||
if let Some(first) = opt
|
if let Some(first) = opt
|
||||||
@ -15,6 +15,17 @@ fn check_if_let(opt: Option<Option<Option<i32>>>, value: i32) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_let_guard(opt: Option<Option<Option<i32>>>, value: i32) -> bool {
|
||||||
|
match opt {
|
||||||
|
Some(first) if let Some(second) = first && let Some(third) = second && third == value => {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn check_while_let(opt: Option<Option<Option<i32>>>, value: i32) -> bool {
|
fn check_while_let(opt: Option<Option<Option<i32>>>, value: i32) -> bool {
|
||||||
while let Some(first) = opt
|
while let Some(first) = opt
|
||||||
&& let Some(second) = first
|
&& let Some(second) = first
|
||||||
@ -30,6 +41,9 @@ fn main() {
|
|||||||
assert_eq!(check_if_let(Some(Some(Some(1))), 1), true);
|
assert_eq!(check_if_let(Some(Some(Some(1))), 1), true);
|
||||||
assert_eq!(check_if_let(Some(Some(Some(1))), 9), false);
|
assert_eq!(check_if_let(Some(Some(Some(1))), 9), false);
|
||||||
|
|
||||||
|
assert_eq!(check_let_guard(Some(Some(Some(1))), 1), true);
|
||||||
|
assert_eq!(check_let_guard(Some(Some(Some(1))), 9), false);
|
||||||
|
|
||||||
assert_eq!(check_while_let(Some(Some(Some(1))), 1), true);
|
assert_eq!(check_while_let(Some(Some(Some(1))), 1), true);
|
||||||
assert_eq!(check_while_let(Some(Some(Some(1))), 9), false);
|
assert_eq!(check_while_let(Some(Some(Some(1))), 9), false);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user