-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lang-items: Add Result and Try lang items
gcc/rust/ChangeLog: * util/rust-lang-item.h: Add handling for Result::Ok, Result::Err, Try, Try::into_result, Try::from_ok, Try::from_err. * util/rust-lang-item.cc: Likewise. gcc/testsuite/ChangeLog: * rust/compile/try-trait.rs: New test.
- Loading branch information
1 parent
289bf52
commit b87fd67
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
enum Result<T, E> { | ||
#[lang = "Ok"] | ||
Ok(T), | ||
#[lang = "Err"] | ||
Err(E) | ||
} | ||
|
||
#[lang = "try"] | ||
pub trait Try { | ||
/// The type of this value when viewed as successful. | ||
#[unstable(feature = "try_trait", issue = "42327")] | ||
type Ok; | ||
/// The type of this value when viewed as failed. | ||
#[unstable(feature = "try_trait", issue = "42327")] | ||
type Error; | ||
|
||
/// Applies the "?" operator. A return of `Ok(t)` means that the | ||
/// execution should continue normally, and the result of `?` is the | ||
/// value `t`. A return of `Err(e)` means that execution should branch | ||
/// to the innermost enclosing `catch`, or return from the function. | ||
/// | ||
/// If an `Err(e)` result is returned, the value `e` will be "wrapped" | ||
/// in the return type of the enclosing scope (which must itself implement | ||
/// `Try`). Specifically, the value `X::from_error(From::from(e))` | ||
/// is returned, where `X` is the return type of the enclosing function. | ||
#[lang = "into_result"] | ||
#[unstable(feature = "try_trait", issue = "42327")] | ||
fn into_result(self) -> Result<Self::Ok, Self::Error>; | ||
|
||
/// Wrap an error value to construct the composite result. For example, | ||
/// `Result::Err(x)` and `Result::from_error(x)` are equivalent. | ||
#[lang = "from_error"] | ||
#[unstable(feature = "try_trait", issue = "42327")] | ||
fn from_error(v: Self::Error) -> Self; | ||
|
||
/// Wrap an OK value to construct the composite result. For example, | ||
/// `Result::Ok(x)` and `Result::from_ok(x)` are equivalent. | ||
#[lang = "from_ok"] | ||
#[unstable(feature = "try_trait", issue = "42327")] | ||
fn from_ok(v: Self::Ok) -> Self; | ||
} |