gotobykkrwhofragsfront matter

[07]entry 7 of 29

gotobykkrwhofrags

open source · Rust2026

this entry is written twice, in full

  1. 1.in brief

    C-style goto for Rust (published crate)

  2. 2.in general

    A proc-macro that brings goto to Rust, safely.

  3. 3.in particular

    Desugars goto into a safe match-driven state machine at compile time. Zero unsafe. On crates.io.

  1. 1.in brief

    a published add-on giving Rust the jump instruction it refuses to have

  2. 2.in general

    Brings the most notorious instruction in programming to a language that deliberately left it out.

  3. 3.in particular

    It rewrites your code while it is being compiled, turning the jumps into an ordinary safe loop. Nothing unsafe, and it is published for anyone to use.


context

Rust1 deliberately has no goto. gotobykkrwhofrags brings it anyway: apply #[goto] to a function and use label!(name) / goto!(name), without unsafe, linker hacks, or runtime overhead beyond the generated loop.

how it works

The attribute macro rewrites the function body at compile time, through eight passes, into a match-driven state machine.

  1. 1.

    Eight compile-time passes: segment splitting, duplicate-label detection, label indexing, optional strict hazard detection, variable hoisting, goto replacement, tail-expression conversion, codegen

  2. 2.

    Backward and forward jumps, dispatch-table control flow, goto inside if/else and match arms

  3. 3.

    Works with regular, unsafe, and generic functions

  4. 4.

    #[goto(strict)] turns forward-goto initializer hazards into compile errors; #[goto(debug)] logs each jump

outcome

Published on crates.io with full docs on docs.rs (MSRV 1.61, MIT), CI on GitHub Actions, and contributor/security docs. LLVM5 often optimizes the generated loop to the same assembly as hand-written control flow.

Rust has no goto for good reasons. It has one anyway now, with docs, CI, an MSRV and a security policy.

context

Rust leaves out the jump instruction on purpose, because it is the classic way to make a program impossible to follow. This puts it back: mark a function, then place labels in it and jump to them. No unsafe code, no tricks at the linking stage, and nothing extra happening while the program runs beyond the loop it generates for you.

how it works

While the program is being compiled, it takes the body of your function apart and rebuilds it as an ordinary loop with a switch inside, in eight passes.

  1. 1.

    Eight passes while compiling: cut the code at the labels, refuse a label used twice, index them, optionally warn about risky jumps, lift the variables somewhere they survive the loop, replace the jumps, sort out the final expression, and write the result.

  2. 2.

    Jumps backwards and forwards, jumping via a table, and jumping from inside branches and matches.

  3. 3.

    Works on ordinary functions, unsafe ones, and generic ones alike.

  4. 4.

    One setting turns a jump that would skip past a variable’s setup into a compile error rather than a surprise; another logs every jump as it happens.

outcome

Published for anyone to install, with full documentation, a stated oldest supported compiler, a permissive licence, automated tests on every change, and notes for contributors and for reporting security problems. The compiler will often reduce the generated loop to exactly the same machine instructions as hand-written control flow, so the convenience is usually free.

Rust has no jump instruction for good reasons. It has one anyway now, with documentation, tests, a supported-version floor and a security policy.