Debian Codegraph @

gcc/testsuite/rust/compile/issue-3382.rs

raw
1 #[lang = "sized"]
2 trait Sized {}
3
4 enum Result<T, E> {
5 #[lang = "Ok"]
6 Ok(T),
7 #[lang = "Err"]
8 Err(E),
9 }
10
11 #[lang = "try"]
12 pub trait Try {
13 /// The type of this value when viewed as successful.
14 // #[unstable(feature = "try_trait", issue = "42327")]
15 type Ok;
16 /// The type of this value when viewed as failed.
17 // #[unstable(feature = "try_trait", issue = "42327")]
18 type Error;
19
20 /// Applies the "?" operator. A return of `Ok(t)` means that the
21 /// execution should continue normally, and the result of `?` is the
22 /// value `t`. A return of `Err(e)` means that execution should branch
23 /// to the innermost enclosing `catch`, or return from the function.
24 ///
25 /// If an `Err(e)` result is returned, the value `e` will be "wrapped"
26 /// in the return type of the enclosing scope (which must itself implement
27 /// `Try`). Specifically, the value `X::from_error(From::from(e))`
28 /// is returned, where `X` is the return type of the enclosing function.
29 #[lang = "into_result"]
30 #[unstable(feature = "try_trait", issue = "42327")]
31 fn into_result(self) -> Result<Self::Ok, Self::Error>;
32
33 /// Wrap an error value to construct the composite result. For example,
34 /// `Result::Err(x)` and `Result::from_error(x)` are equivalent.
35 #[lang = "from_error"]
36 #[unstable(feature = "try_trait", issue = "42327")]
37 fn from_error(v: Self::Ok) -> Self;
38
39 /// Wrap an OK value to construct the composite result. For example,
40 /// `Result::Ok(x)` and `Result::from_ok(x)` are equivalent.
41 #[lang = "from_ok"]
42 #[unstable(feature = "try_trait", issue = "42327")]
43 fn from_ok(v: Self::Error) -> Self;
44 }
45
46 impl<T, E> Try for Result<T, E> {
47 type Ok = T;
48 type Error = E;
49
50 fn into_result(self) -> Result<T, E> {
51 self
52 }
53
54 fn from_ok(v: T) -> Self {
55 Result::Ok(v)
56 }
57
58 fn from_error(v: E) -> Self {
59 Result::Err(v)
60 }
61 }