diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 25ca33a3d5011..c8f5399a6f7af 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -154,16 +154,15 @@ macro_rules! debug_assert_eq { } /// Short circuiting evaluation on Err -/// -/// `libstd` contains a more general `try!` macro that uses `From`. #[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)), } }) } diff --git a/src/libcore/result.rs b/src/libcore/result.rs index fe0fdb5baa5f3..8b9571e7461d1 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -223,6 +223,8 @@ //! } //! ``` //! +//! (The real `try!` macro uses `From` 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.