News for hackers. Stuff that matters.
Re:Rustc: Add do yeet expressions to allow experimentation i... by Tuna-Fish on Friday May 06, 2022 @12:27PM (#31287047)
It's a bunch of syntax sugar. The proposal is that instead of typing this:

    fn foo(b : bool) -> Result<Bar,Baz> {
        ...
        return Ok(bar);
        ...
        return Err(baz);
    }
you can type:

    fn foo() -> Bar throws Baz {
        ...
        return bar;
        ...
        throw baz; //or yeet, in this proposal
    }
and it works exactly identically as the first example. ? still works inside the function just as it normally would. I find the proposal sort of pointless, but also totally harmless, so why not.
Re:Rustc: Add do yeet expressions to allow experimentation i... by CryZe on Friday May 06, 2022 @02:46PM (#31288496)
That's not all it does. It "breaks" to the nearest "try" barrier. It's basically the desugaring of the Err branch in the ? operator, that you can't currently express yourself. It's mostly relevant for try blocks. I guess you'd most commonly see this in "control flow like" macros that are similar to the ? operator, like various assertion macros that want to "yeet" an error in case the assertion fails (instead of panicking like those in std).

So in a sense it actually is very similar to `throw` in traditional languages, as it can be caught inside the same function and isn't forced to `return` the error outside the function.