about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-01-20 23:37:35 +0100
committerGitHub <noreply@github.com>2022-01-20 23:37:35 +0100
commit0a9aaec8ebcc7e00bdd02fe196ae7f2e76db2c68 (patch)
tree09dd7f8428c71725449d1d2253a8be83c42a12d8 /src/test
parent35a53b229f383db60eac08b19338424c45f4206a (diff)
parentf491a9f601a8ad0efe7f38de5b807a2c07774ae1 (diff)
downloadrust-0a9aaec8ebcc7e00bdd02fe196ae7f2e76db2c68.tar.gz
rust-0a9aaec8ebcc7e00bdd02fe196ae7f2e76db2c68.zip
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`
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.rs12
-rw-r--r--src/test/ui/rfc-2497-if-let-chains/then-else-blocks.rs16
2 files changed, 26 insertions, 2 deletions
diff --git a/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.rs b/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.rs
index 5915cb9df26..945c665e35d 100644
--- a/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.rs
+++ b/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.rs
@@ -1,6 +1,6 @@
 // check-pass
 
-#![feature(let_chains)]
+#![feature(if_let_guard, let_chains)]
 
 use std::ops::Range;
 
@@ -16,6 +16,16 @@ fn main() {
         && 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 Some(ref first) = opt && let second = first && let _third = second {
diff --git a/src/test/ui/rfc-2497-if-let-chains/then-else-blocks.rs b/src/test/ui/rfc-2497-if-let-chains/then-else-blocks.rs
index 0856a105206..e061174f667 100644
--- a/src/test/ui/rfc-2497-if-let-chains/then-else-blocks.rs
+++ b/src/test/ui/rfc-2497-if-let-chains/then-else-blocks.rs
@@ -1,6 +1,6 @@
 // run-pass
 
-#![feature(let_chains)]
+#![feature(if_let_guard, let_chains)]
 
 fn check_if_let(opt: Option<Option<Option<i32>>>, value: i32) -> bool {
     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 {
     while let Some(first) = opt
         && 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))), 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))), 9), false);
 }