1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![feature(catch_expr)]
16 let catch_result = do catch {
20 assert_eq!(catch_result, 5);
23 while catch { catch = false; }
24 assert_eq!(catch, false);
26 catch = if catch { false } else { true };
27 assert_eq!(catch, true);
33 let catch_err = do catch {
37 assert_eq!(catch_err, Err(22));
39 let catch_okay: Result<i32, i32> = do catch {
40 if false { Err(25)?; }
44 assert_eq!(catch_okay, Ok(28));
46 let catch_from_loop: Result<i32, i32> = do catch {
48 if i < 5 { Ok::<i32, i32>(i)?; } else { Err(i)?; }
52 assert_eq!(catch_from_loop, Err(5));
55 let _res: Result<(), ()> = do catch {
59 assert_eq!(cfg_init, 5);
62 let _res: Result<(), ()> = do catch {
67 assert_eq!(cfg_init_2, 6);
69 let my_string = "test".to_string();
70 let res: Result<&str, ()> = do catch {
73 assert_eq!(res, Ok("test"));