about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-03-14 10:40:09 +0000
committerbors <bors@rust-lang.org>2017-03-14 10:40:09 +0000
commit6f10e2f63de720468e2b4bfcb275e4b90b1f9870 (patch)
tree11f51d7f07c5a74ab22e20b7f3556c4c0191fe66 /src/test
parentfa53235cc4364fe085ccba720237d19b669c2f8b (diff)
parentb1aa99352a69e328094e096bbbd1741b68c0667f (diff)
downloadrust-6f10e2f63de720468e2b4bfcb275e4b90b1f9870.tar.gz
rust-6f10e2f63de720468e2b4bfcb275e4b90b1f9870.zip
Auto merge of #39921 - cramertj:add-catch-to-ast, r=nikomatsakis
Add catch {} to AST

Part of #39849. Builds on #39864.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/catch-in-match.rs15
-rw-r--r--src/test/compile-fail/catch-in-while.rs15
-rw-r--r--src/test/compile-fail/feature-gate-catch_expr.rs17
-rw-r--r--src/test/run-pass/catch-expr.rs32
4 files changed, 79 insertions, 0 deletions
diff --git a/src/test/compile-fail/catch-in-match.rs b/src/test/compile-fail/catch-in-match.rs
new file mode 100644
index 00000000000..9f9968e8124
--- /dev/null
+++ b/src/test/compile-fail/catch-in-match.rs
@@ -0,0 +1,15 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(catch_expr)]
+
+fn main() {
+    match do catch { false } { _ => {} } //~ ERROR expected expression, found reserved keyword `do`
+}
diff --git a/src/test/compile-fail/catch-in-while.rs b/src/test/compile-fail/catch-in-while.rs
new file mode 100644
index 00000000000..cb8613ee60b
--- /dev/null
+++ b/src/test/compile-fail/catch-in-while.rs
@@ -0,0 +1,15 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(catch_expr)]
+
+fn main() {
+    while do catch { false } {} //~ ERROR expected expression, found reserved keyword `do`
+}
diff --git a/src/test/compile-fail/feature-gate-catch_expr.rs b/src/test/compile-fail/feature-gate-catch_expr.rs
new file mode 100644
index 00000000000..5568a5cf0aa
--- /dev/null
+++ b/src/test/compile-fail/feature-gate-catch_expr.rs
@@ -0,0 +1,17 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub fn main() {
+    let catch_result = do catch { //~ ERROR `catch` expression is experimental
+        let x = 5;
+        x
+    };
+    assert_eq!(catch_result, 5);
+}
diff --git a/src/test/run-pass/catch-expr.rs b/src/test/run-pass/catch-expr.rs
new file mode 100644
index 00000000000..a9b28a534a3
--- /dev/null
+++ b/src/test/run-pass/catch-expr.rs
@@ -0,0 +1,32 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(catch_expr)]
+
+struct catch {}
+
+pub fn main() {
+    let catch_result = do catch {
+        let x = 5;
+        x
+    };
+    assert_eq!(catch_result, 5);
+
+    let mut catch = true;
+    while catch { catch = false; }
+    assert_eq!(catch, false);
+
+    catch = if catch { false } else { true };
+    assert_eq!(catch, true);
+
+    match catch {
+        _ => {}
+    };
+}