|
| 1 | +// Copyright 2018 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. |
| 4 | +// |
| 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. |
| 10 | + |
| 11 | +// compile-flags:--test |
| 12 | + |
| 13 | +/// ```rust,edition2018 |
| 14 | +/// #![feature(try_blocks)] |
| 15 | +/// |
| 16 | +/// use std::num::ParseIntError; |
| 17 | +/// |
| 18 | +/// let result: Result<i32, ParseIntError> = try { |
| 19 | +/// "1".parse::<i32>()? |
| 20 | +/// + "2".parse::<i32>()? |
| 21 | +/// + "3".parse::<i32>()? |
| 22 | +/// }; |
| 23 | +/// assert_eq!(result, Ok(6)); |
| 24 | +/// |
| 25 | +/// let result: Result<i32, ParseIntError> = try { |
| 26 | +/// "1".parse::<i32>()? |
| 27 | +/// + "foo".parse::<i32>()? |
| 28 | +/// + "3".parse::<i32>()? |
| 29 | +/// }; |
| 30 | +/// assert!(result.is_err()); |
| 31 | +/// ``` |
| 32 | +
|
| 33 | + |
| 34 | +/// ```rust,edition2015,compile_fail,E0574 |
| 35 | +/// #![feature(try_blocks)] |
| 36 | +/// |
| 37 | +/// use std::num::ParseIntError; |
| 38 | +/// |
| 39 | +/// let result: Result<i32, ParseIntError> = try { |
| 40 | +/// "1".parse::<i32>()? |
| 41 | +/// + "2".parse::<i32>()? |
| 42 | +/// + "3".parse::<i32>()? |
| 43 | +/// }; |
| 44 | +/// assert_eq!(result, Ok(6)); |
| 45 | +/// |
| 46 | +/// let result: Result<i32, ParseIntError> = try { |
| 47 | +/// "1".parse::<i32>()? |
| 48 | +/// + "foo".parse::<i32>()? |
| 49 | +/// + "3".parse::<i32>()? |
| 50 | +/// }; |
| 51 | +/// assert!(result.is_err()); |
| 52 | +/// ``` |
| 53 | +
|
| 54 | +pub fn foo() {} |
0 commit comments