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.
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 // compile-flags:--test
13 /// ```rust,edition2018
14 /// #![feature(try_blocks)]
16 /// use std::num::ParseIntError;
18 /// let result: Result<i32, ParseIntError> = try {
19 /// "1".parse::<i32>()?
20 /// + "2".parse::<i32>()?
21 /// + "3".parse::<i32>()?
23 /// assert_eq!(result, Ok(6));
25 /// let result: Result<i32, ParseIntError> = try {
26 /// "1".parse::<i32>()?
27 /// + "foo".parse::<i32>()?
28 /// + "3".parse::<i32>()?
30 /// assert!(result.is_err());
34 /// ```rust,edition2015,compile_fail,E0574
35 /// #![feature(try_blocks)]
37 /// use std::num::ParseIntError;
39 /// let result: Result<i32, ParseIntError> = try {
40 /// "1".parse::<i32>()?
41 /// + "2".parse::<i32>()?
42 /// + "3".parse::<i32>()?
44 /// assert_eq!(result, Ok(6));
46 /// let result: Result<i32, ParseIntError> = try {
47 /// "1".parse::<i32>()?
48 /// + "foo".parse::<i32>()?
49 /// + "3".parse::<i32>()?
51 /// assert!(result.is_err());