Skip to content

Convert errors in libcore’s try! macro too. #28722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,15 @@ macro_rules! debug_assert_eq {
}

/// Short circuiting evaluation on Err
///
/// `libstd` contains a more general `try!` macro that uses `From<E>`.
#[macro_export]
macro_rules! try {
($e:expr) => ({
use $crate::result::Result::{Ok, Err};
use $crate::convert::From;

match $e {
Ok(e) => e,
Err(e) => return Err(e),
Err(e) => return Err(From::from(e)),
}
})
}
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@
//! }
//! ```
//!
//! (The real `try!` macro uses `From<E>` to convert between error types automatically.)
//!
//! `try!` is imported by the prelude and is available everywhere, but it can only
//! be used in functions that return `Result` because of the early return of
//! `Err` that it provides.
Expand Down