Skip to content

Commit 0a9aaec

Browse files
authored
Rollup merge of #93086 - c410-f3r:let-guard, r=Mark-Simulacrum
Add tests to ensure that `let_chains` works with `if_let_guard` The current machinery already makes such combination possible but lacks tests. cc `@matthewjasper`
2 parents 35a53b2 + f491a9f commit 0a9aaec

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// check-pass
22

3-
#![feature(let_chains)]
3+
#![feature(if_let_guard, let_chains)]
44

55
use std::ops::Range;
66

@@ -16,6 +16,16 @@ fn main() {
1616
&& let None = local_start {
1717
}
1818

19+
match opt {
20+
Some(ref first) if let second = first && let _third = second => {},
21+
_ => {}
22+
}
23+
match opt {
24+
Some(ref first) if let Range { start: local_start, end: _ } = first
25+
&& let None = local_start => {},
26+
_ => {}
27+
}
28+
1929
while let first = &opt && let Some(ref second) = first && let None = second.start {
2030
}
2131
while let Some(ref first) = opt && let second = first && let _third = second {

src/test/ui/rfc-2497-if-let-chains/then-else-blocks.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-pass
22

3-
#![feature(let_chains)]
3+
#![feature(if_let_guard, let_chains)]
44

55
fn check_if_let(opt: Option<Option<Option<i32>>>, value: i32) -> bool {
66
if let Some(first) = opt
@@ -15,6 +15,17 @@ fn check_if_let(opt: Option<Option<Option<i32>>>, value: i32) -> bool {
1515
}
1616
}
1717

18+
fn check_let_guard(opt: Option<Option<Option<i32>>>, value: i32) -> bool {
19+
match opt {
20+
Some(first) if let Some(second) = first && let Some(third) = second && third == value => {
21+
true
22+
}
23+
_ => {
24+
false
25+
}
26+
}
27+
}
28+
1829
fn check_while_let(opt: Option<Option<Option<i32>>>, value: i32) -> bool {
1930
while let Some(first) = opt
2031
&& let Some(second) = first
@@ -30,6 +41,9 @@ fn main() {
3041
assert_eq!(check_if_let(Some(Some(Some(1))), 1), true);
3142
assert_eq!(check_if_let(Some(Some(Some(1))), 9), false);
3243

44+
assert_eq!(check_let_guard(Some(Some(Some(1))), 1), true);
45+
assert_eq!(check_let_guard(Some(Some(Some(1))), 9), false);
46+
3347
assert_eq!(check_while_let(Some(Some(Some(1))), 1), true);
3448
assert_eq!(check_while_let(Some(Some(Some(1))), 9), false);
3549
}

0 commit comments

Comments
 (0)