failure icon indicating copy to clipboard operation
failure copied to clipboard

bail macro in try block

Open kgv opened this issue 5 years ago • 4 comments

What do you think about changing the bail macro for use it or ensure in the try-blocks?

current:

#[macro_export]
macro_rules! bail {
    ($e:expr) => {
        return Err($crate::err_msg($e));
    };
    ($fmt:expr, $($arg:tt)+) => {
        return Err($crate::err_msg(format!($fmt, $($arg)+)));
    };
}

changed:

#[macro_export]
macro_rules! bail {
    ($e:expr) => {
        Err($crate::err_msg($e))?;
    };
    ($fmt:expr, $($arg:tt)+) => {
        Err($crate::err_msg(format!($fmt, $($arg)+)))?;
    };
}

kgv avatar Sep 21 '18 10:09 kgv

@kgv I didn't realize try {} blocks were available already! Do you have any links to (nightly) docs / feature tracking issues? It would probably help provide some context for anyone that hasn't caught up on the latest around try {} (e.g. people like me, haha). Thanks!

yoshuawuyts avatar Sep 21 '18 10:09 yoshuawuyts

@yoshuawuyts try-blocks

kgv avatar Sep 21 '18 10:09 kgv

I think I'm in favour of this change. Would accept a PR if it comes with tests.

mitsuhiko avatar Oct 01 '18 19:10 mitsuhiko

Would also fix https://github.com/rust-lang-nursery/failure/issues/110 which just tripped me up as unobvious (bail! is strictly less versatile than ?)

bossmc avatar Jan 02 '19 18:01 bossmc