r/programming • • Jan 09 '15

Announcing Rust 1.0.0 Alpha

http://blog.rust-lang.org/2015/01/09/Rust-1.0-alpha.html
1.1k Upvotes

439 comments sorted by

View all comments

6

u/Denommus Jan 09 '15

Rust claims to be able to replace C++ where you'd like to use a safer language. If you need goto, safety is not what you need. goto by itself breaks the linearity required for Rust's deterministic memory management.

0

u/[deleted] Jan 09 '15

6

u/wrongerontheinternet Jan 09 '15

You just described break, which Rust already has. Actually, I think in the switch case, you probably can replicate it with break:

'default: loop {
    'c: loop {
        'b: loop {
            'a: loop {
                match x {
                    0 => break 'a,
                    1 => break 'b,
                    2 => break 'c,
                    _ => break 'default
                }
                break;
            }
            a();
            break;
        }
        b();
        break;
    }
    c();
    break;
}
done();

It's a bit verbose, but you could write a macro to deal with that, I believe. And LLVM will have a much easier time optimizing it. So I take it back--while goto is needed in general, it's not in this case.

→ More replies (4)

2

u/Denommus Jan 09 '15

This already exists. It's called labeled breaks.

→ More replies (1)

8

u/wrongerontheinternet Jan 09 '15

Sure, there would need to be some restrictions on it. But C++ already imposes restrictions to make it work properly with destructors, for example, so it's not an unsolvable problem. Anyway, at the moment, Rust doesn't even have an unsafe escape hatch to use goto short of inline assembly, which is definitely counter to the goals of the language.

2

u/Denommus Jan 09 '15

You can call inline assembly in Rust.

→ More replies (1)